Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8324641: [IR Framework] Add Setup method to provide custom arguments and set fields #17557

Closed
wants to merge 38 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
f8845ec
8324641
eme64 Jan 24, 2024
42205ee
example is working
eme64 Jan 24, 2024
3eb7c18
Arguments values works again as well
eme64 Jan 24, 2024
62d907b
remove printFixedRandomArguments
eme64 Jan 24, 2024
8f6fe27
Adjusted all @Arguments with value
eme64 Jan 24, 2024
f0c6cd8
improve some comments
eme64 Jan 24, 2024
2a57e52
improve formatting and comments
eme64 Jan 25, 2024
d4d15d8
index -> invocationCounter
eme64 Jan 25, 2024
461405d
SetupExample.java
eme64 Jan 25, 2024
08670a5
make invocationCounter optional for Setup method
eme64 Jan 29, 2024
b725b29
fix trailing whitespaces
eme64 Jan 29, 2024
13c6621
update readme
eme64 Jan 29, 2024
b367647
add SetupInfo class
eme64 Jan 29, 2024
1f8f57a
fix up some tests
eme64 Jan 29, 2024
24eb09d
fix add and comma
eme64 Feb 1, 2024
1237c02
for Review by Christian
eme64 Feb 5, 2024
852e6e1
more for Christian
eme64 Feb 5, 2024
66c3ef7
setup string not list, for Christian
eme64 Feb 5, 2024
fddcdfe
made ArgumentsProvider an interface
eme64 Feb 5, 2024
8ff7dfa
fix more comments
eme64 Feb 5, 2024
e9d0106
Apply suggestions from code review
eme64 Feb 6, 2024
164665f
fix whitespace from last commit
eme64 Feb 6, 2024
12c9a45
Apply suggestions from code review
eme64 Feb 6, 2024
a1dda56
Apply suggestions from code review
eme64 Feb 6, 2024
3206074
rename BaseTestExample -> NormalTestExample
eme64 Feb 6, 2024
af5e7dc
add paragraph for Christian
eme64 Feb 6, 2024
b37b748
wip more tests
eme64 Feb 6, 2024
6efd271
wip: more tests
eme64 Feb 7, 2024
252815e
wip: more tests and fixes
eme64 Feb 7, 2024
d10fba5
wip: test fields and invocationCounter
eme64 Feb 7, 2024
4a8f96b
wip: throw tests, array tests, random tests
eme64 Feb 7, 2024
1f84ef5
improved and simplified examples
eme64 Feb 7, 2024
33029f6
remove tabs
eme64 Feb 7, 2024
f03f3b8
Apply suggestions from code review
eme64 Feb 8, 2024
47b8d25
more for Christian
eme64 Feb 8, 2024
617e40a
fix whitespace
eme64 Feb 8, 2024
b62b7ef
Merge branch 'master' into JDK-8324641
eme64 Feb 8, 2024
1f7872a
Merge branch 'master' into JDK-8324641
eme64 Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -57,12 +57,32 @@ public static void main(String[] args) {
Asserts.fail("Should have thrown exception");
} catch (TestVMException e) {
System.setOut(oldOut);
Asserts.assertTrue(e.getExceptionInfo().contains("Test Failures (2)"));
Asserts.assertTrue(e.getExceptionInfo().contains("testTooManyArgs"));
Asserts.assertTrue(e.getExceptionInfo().contains("IllegalArgumentException: wrong number of arguments: 3 expected: 1"));
Asserts.assertTrue(e.getExceptionInfo().contains("testTooFewArgs"));
Asserts.assertTrue(e.getExceptionInfo().split("There was an error while invoking @Test").length == 3);
Asserts.assertTrue(e.getExceptionInfo().contains("IllegalArgumentException: wrong number of arguments: 2 expected: 3"));

Asserts.assertTrue(e.getExceptionInfo().contains("setupTestBadSetupArgsTooMany"));
Asserts.assertTrue(e.getExceptionInfo().contains("wrong number of arguments: 0 expected: 2"));
Asserts.assertTrue(e.getExceptionInfo().contains("setupTestBadSetupArgsWrongType"));
Asserts.assertTrue(e.getExceptionInfo().contains("argument type mismatch"));

Asserts.assertTrue(e.getExceptionInfo().contains("setupReturnIntArray"));
Asserts.assertTrue(e.getExceptionInfo().contains("class [I cannot be cast to class [Ljava.lang.Object;"));
Asserts.assertTrue(e.getExceptionInfo().contains("setupReturnInt"));
Asserts.assertTrue(e.getExceptionInfo().contains("class java.lang.Integer cannot be cast to class [Ljava.lang.Object;"));

Asserts.assertTrue(e.getExceptionInfo().contains("testSetupWrongArgumentType"));
Asserts.assertTrue(e.getExceptionInfo().contains("argument type mismatch"));

// Check number of total failures:
Asserts.assertEQ(e.getExceptionInfo().split("argument type mismatch").length - 1, 2);
Asserts.assertEQ(e.getExceptionInfo().split("There was an error while invoking setup").length - 1, 4);
Asserts.assertEQ(e.getExceptionInfo().split("There was an error while invoking @Test").length - 1, 3);
Asserts.assertTrue(e.getExceptionInfo().contains("Test Failures (7)"));
}

// TODO make sure asserts from setup get out properly
// // Negative test with run into TestRunException
// System.setOut(ps);
// try {
@@ -78,11 +98,17 @@ public static void main(String[] args) {
// TODO investigate if the values are really right here, e.g. if fields are set
// TODO try other bad return values
@Setup
public void setupTestGood1() {}
public void setupVoid() {}

@Test
@Arguments(setup = "setupTestGood1")
public void testGood1() {}
@Arguments(setup = "setupVoid")
public void testSetupVoid() {}

// TODO
// - SetupInfo
// - Object only used once
// - move the examples here, make examples more "real examples"


// @Test
// @IR(counts = {IRNode.STORE_I, "1"})
@@ -125,11 +151,12 @@ public void testGood1() {}
}

class TestSetupTestsWithExpectedExceptions {
// ----------------- wrong number of arguments ------------------
@Setup
public Object[] setupTooManyArgs() {
return new Object[]{1, 2, 3};
}

@Test
@Arguments(setup = "setupTooManyArgs")
public void testTooManyArgs(int a) {}
@@ -138,10 +165,59 @@ public void testTooManyArgs(int a) {}
public Object[] setupTooFewArgs() {
return new Object[]{1, 2};
}

@Test
@Arguments(setup = "setupTooFewArgs")
public void testTooFewArgs(int a, int b, int c) {}

// ----------------- wrong arguments for setup ------------------
@Setup
public Object[] setupTestBadSetupArgsTooMany(SetupInfo setupInfo, int bad) {
return new Object[]{1, 2};
}

@Test
@Arguments(setup = "setupTestBadSetupArgsTooMany")
public void testBadSetupArgsTooMany(int a, int b) {}

@Setup
public Object[] setupTestBadSetupArgsWrongType(int bad) {
return new Object[]{1, 2};
}

@Test
@Arguments(setup = "setupTestBadSetupArgsWrongType")
public void testBadSetupArgsWrongType(int a, int b) {}

// ----------------- setup wrong return type ------------------
@Setup
public int[] setupReturnIntArray() {
return new int[]{1, 2, 3};
}

@Test
@Arguments(setup = "setupReturnIntArray")
public void testSetupReturnIntArray(int a, int b, int c) {}

@Setup
public int setupReturnInt(SetupInfo setupInfo) {
return setupInfo.invocationCounter();
}

@Test
@Arguments(setup = "setupReturnInt")
public void testSetupReturnInt(int a) {}

// ----------------- setup provides wrong argument types ------
@Setup
public Object[] setupWrongArgumentType(SetupInfo setupInfo) {
return new Object[]{(int)1, (long)2};
}

@Test
@Arguments(setup = "setupWrongArgumentType")
public void testSetupWrongArgumentType(long a, int b) {}

}

// class TestSetupTestsWithBadRunExceptions {