59 private static final String RETURN_S = "return \"Hello\";";
60 private static final String CONTINUE_N = "continue;";
61 private static final String CONTINUE_L = "continue label;";
62 private static final String NOTHING = "System.out.println();";
63
64 // containers that do not require exhaustiveness
65 private static final List<String> CONTAINERS
66 = List.of(RUNNABLE, FOR, WHILE, DO, SSWITCH, IF, BLOCK);
67 // containers that do not require exhaustiveness that are statements
68 private static final List<String> CONTAINER_STATEMENTS
69 = List.of(FOR, WHILE, DO, SSWITCH, IF, BLOCK);
70
71 @AfterMethod
72 public void dumpTemplateIfError(ITestResult result) {
73 // Make sure offending template ends up in log file on failure
74 if (!result.isSuccess()) {
75 System.err.printf("Diagnostics: %s%nTemplate: %s%n", diags.errorKeys(), sourceFiles.stream().map(p -> p.snd).collect(toList()));
76 }
77 }
78
79 private static String[] PREVIEW_OPTIONS = {"--enable-preview", "-source",
80 Integer.toString(Runtime.version().feature())};
81
82 private void program(String... constructs) {
83 String s = "class C { static boolean cond = false; static int x = 0; void m() { # } }";
84 for (String c : constructs)
85 s = s.replace("#", c);
86 addSourceFile("C.java", new StringTemplate(s));
87 }
88
89 private void assertOK(String... constructs) {
90 reset();
91 addCompileOptions(PREVIEW_OPTIONS);
92 program(constructs);
93 try {
94 compile();
95 }
96 catch (IOException e) {
97 throw new RuntimeException(e);
98 }
99 assertCompileSucceeded();
100 }
101
102 private void assertOKWithWarning(String warning, String... constructs) {
103 reset();
104 addCompileOptions(PREVIEW_OPTIONS);
105 program(constructs);
106 try {
107 compile();
108 }
109 catch (IOException e) {
110 throw new RuntimeException(e);
111 }
112 assertCompileSucceededWithWarning(warning);
113 }
114
115 private void assertFail(String expectedDiag, String... constructs) {
116 reset();
117 addCompileOptions(PREVIEW_OPTIONS);
118 program(constructs);
119 try {
120 compile();
121 }
122 catch (IOException e) {
123 throw new RuntimeException(e);
124 }
125 assertCompileFailed(expectedDiag);
126 }
127
128 public void testReallySimpleCases() {
129 for (String s : CONTAINERS)
130 assertOK(s, NOTHING);
131 for (String s : CONTAINER_STATEMENTS)
132 assertOK(LABEL, s, NOTHING);
133 }
134
135 public void testLambda() {
136 assertOK(RUNNABLE, RETURN_N);
137 assertOK(RUNNABLE, NOTHING);
|
59 private static final String RETURN_S = "return \"Hello\";";
60 private static final String CONTINUE_N = "continue;";
61 private static final String CONTINUE_L = "continue label;";
62 private static final String NOTHING = "System.out.println();";
63
64 // containers that do not require exhaustiveness
65 private static final List<String> CONTAINERS
66 = List.of(RUNNABLE, FOR, WHILE, DO, SSWITCH, IF, BLOCK);
67 // containers that do not require exhaustiveness that are statements
68 private static final List<String> CONTAINER_STATEMENTS
69 = List.of(FOR, WHILE, DO, SSWITCH, IF, BLOCK);
70
71 @AfterMethod
72 public void dumpTemplateIfError(ITestResult result) {
73 // Make sure offending template ends up in log file on failure
74 if (!result.isSuccess()) {
75 System.err.printf("Diagnostics: %s%nTemplate: %s%n", diags.errorKeys(), sourceFiles.stream().map(p -> p.snd).collect(toList()));
76 }
77 }
78
79 private void program(String... constructs) {
80 String s = "class C { static boolean cond = false; static int x = 0; void m() { # } }";
81 for (String c : constructs)
82 s = s.replace("#", c);
83 addSourceFile("C.java", new StringTemplate(s));
84 }
85
86 private void assertOK(String... constructs) {
87 reset();
88 addCompileOptions();
89 program(constructs);
90 try {
91 compile();
92 }
93 catch (IOException e) {
94 throw new RuntimeException(e);
95 }
96 assertCompileSucceeded();
97 }
98
99 private void assertOKWithWarning(String warning, String... constructs) {
100 reset();
101 addCompileOptions();
102 program(constructs);
103 try {
104 compile();
105 }
106 catch (IOException e) {
107 throw new RuntimeException(e);
108 }
109 assertCompileSucceededWithWarning(warning);
110 }
111
112 private void assertFail(String expectedDiag, String... constructs) {
113 reset();
114 addCompileOptions();
115 program(constructs);
116 try {
117 compile();
118 }
119 catch (IOException e) {
120 throw new RuntimeException(e);
121 }
122 assertCompileFailed(expectedDiag);
123 }
124
125 public void testReallySimpleCases() {
126 for (String s : CONTAINERS)
127 assertOK(s, NOTHING);
128 for (String s : CONTAINER_STATEMENTS)
129 assertOK(LABEL, s, NOTHING);
130 }
131
132 public void testLambda() {
133 assertOK(RUNNABLE, RETURN_N);
134 assertOK(RUNNABLE, NOTHING);
|