1010import java .nio .charset .StandardCharsets ;
1111import java .nio .file .Files ;
1212import java .nio .file .Path ;
13+ import java .nio .file .Paths ;
1314import java .util .*;
1415import java .nio .file .Paths ;
1516import java .util .ArrayList ;
1617import java .util .List ;
1718import java .util .Properties ;
19+ import java .util .stream .Stream ;
1820
1921import de .uka .ilkd .key .control .DefaultUserInterfaceControl ;
2022import de .uka .ilkd .key .control .KeYEnvironment ;
3133import org .key_project .prover .sequent .Sequent ;
3234import org .key_project .util .Streams ;
3335
34- import com .fasterxml .jackson .core .type .TypeReference ;
3536import com .fasterxml .jackson .databind .ObjectMapper ;
3637import com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
3738import org .assertj .core .api .Assertions ;
3839import org .jspecify .annotations .NonNull ;
3940import org .jspecify .annotations .Nullable ;
4041import org .junit .jupiter .api .Assumptions ;
41- import org .junit .jupiter .params .ParameterizedTest ;
42- import org .junit .jupiter .params .provider .Arguments ;
43- import org .junit .jupiter .params .provider .MethodSource ;
42+ import org .junit .jupiter .api .DynamicTest ;
43+ import org .junit .jupiter .api .TestFactory ;
4444import org .slf4j .Logger ;
4545import org .slf4j .LoggerFactory ;
4646
5656 */
5757public class MasterHandlerTest {
5858 /**
59- * If this variable is set when running this test class, then those cases with expected result
60- * "weak_valid" will raise an exception unless they can be proved using the solver.
59+ * If this variable is set when running this test class, then those cases with
60+ * expected result
61+ * "weak_valid" will raise an exception unless they can be proved using the
62+ * solver.
6163 * <p>
62- * Otherwise, a "timeout" or "unknown" is accepted. This can be used to deal with test cases
64+ * Otherwise, a "timeout" or "unknown" is accepted. This can be used to deal
65+ * with test cases
6366 * that
6467 * should verify but do not yet do so.
6568 * <p>
@@ -73,53 +76,76 @@ public class MasterHandlerTest {
7376 && it .getName ().equals ("Z3 (Legacy Translation)" ))
7477 .findFirst ().orElse (null );
7578
76- public static List <Arguments > data ()
79+ private static List <LoadedTestData > data = null ;
80+
81+ public static List <LoadedTestData > data ()
7782 throws IOException , URISyntaxException , ProblemLoaderException {
78- try (var input = MasterHandlerTest .class .getResourceAsStream ("cases.yml" )) {
79- var om = new ObjectMapper (new YAMLFactory ());
80- TypeReference <HashMap <String , TestData >> typeRef = new TypeReference <>() {
81- };
82- Map <String , TestData > preData = om .readValue (input , typeRef );
83- var result = new ArrayList <Arguments >(preData .size ());
84- for (var entry : preData .entrySet ()) {
85- final var value = entry .getValue ();
86-
87- if (value .state == TestDataState .IGNORE ) {
88- LOGGER .info ("Test {} case has been marked ignore" , entry .getKey ());
89- continue ;
90- }
83+ if (data != null )
84+ return data ;
85+
86+ var om = new ObjectMapper (new YAMLFactory ());
87+ var path = Paths .get ("src/test/resources/de/uka/ilkd/key/smt/newsmt2/cases/" );
88+ try (var walker = Files .walk (path )) {
89+ List <Path > files =
90+ walker .filter (it -> it .getFileName ().toString ().endsWith (".yml" )).toList ();
91+ data = new ArrayList <>(files .size ());
92+
93+ for (Path pFile : files ) {
94+ try {
95+ var file = pFile .toFile ();
96+
97+ TestData value = om .readValue (file , TestData .class );
98+
99+ if (value .state == TestDataState .IGNORE ) {
100+ LOGGER .info ("Test {} case has been marked ignore" , file );
101+ continue ;
102+ }
91103
92- final var testData = value .load (entry .getKey ());
93- result .add (Arguments .of (testData ));
104+ System .err .println (pFile );
105+ final var testData = value .load (file .getName ().replace (".yml" , "" ));
106+ data .add (testData );
107+
108+ } catch (Exception e ) {
109+ e .printStackTrace ();
110+ throw e ;
111+ }
94112 }
95- return result ;
113+ System .out .println (data );
114+ return data ;
96115 }
97116 }
98117
118+ /**
119+ * Describes the state of a test instance.
120+ */
99121 public enum TestDataState {
100122 EMPTY , EXTENDED , IGNORE
101123 }
102124
125+ /**
126+ * Expected outcome of a test instance.
127+ */
103128 public enum Expectation {
104129 VALID , FAIL , IRRELEVANT
105130 }
106131
107132 /**
108- * This class contains the information about the test fixtures that is loaded via the YAML.
109- * @param contains a list of strings that are expected in the SMT translation
133+ * This class contains the information about the test fixtures that is loaded
134+ * via the YAML.
135+ *
136+ * @param contains a list of strings that are expected in the SMT translation
110137 * @param smtSettings required key/values in the smt settings.
111- * @param expected expected output of Z3
112- * @param state state of the test
113- * @param javaSrc path to necessary java sources
114- * @param keySrc contents of the key file to be loaded.
138+ * @param expected expected output of Z3
139+ * @param state state of the test
140+ * @param javaSrc path to necessary java sources
141+ * @param keySrc contents of the key file to be loaded.
115142 */
116143 public record TestData (List <String > contains ,
117- Properties smtSettings ,
118- Expectation expected ,
119- TestDataState state ,
120- String javaSrc ,
121- String keySrc
122- ) {
144+ Properties smtSettings ,
145+ Expectation expected ,
146+ TestDataState state ,
147+ String javaSrc ,
148+ String keySrc ) {
123149
124150 private LoadedTestData load (String name ) throws IOException , ProblemLoaderException {
125151 var keySrc = keySrc ();
@@ -148,6 +174,7 @@ private LoadedTestData load(String name) throws IOException, ProblemLoaderExcept
148174
149175 ModularSMTLib2Translator translator = new ModularSMTLib2Translator ();
150176 var translation = translator .translateProblem (sequent , env .getServices (), settings ).toString ();
177+ env .dispose ();
151178 return new LoadedTestData (name , this , translation );
152179 }
153180 }
@@ -159,8 +186,12 @@ private record LoadedTestData(String name, TestData data, String translation) {
159186 }
160187 }
161188
162- @ ParameterizedTest
163- @ MethodSource ("data" )
189+ @ TestFactory
190+ Stream <DynamicTest > testTranslation () throws Exception {
191+ return data ().stream ()
192+ .map (it -> DynamicTest .dynamicTest (it .name , () -> testTranslation (it )));
193+ }
194+
164195 void testTranslation (LoadedTestData data ) throws Exception {
165196 if (DUMP_SMT ) {
166197 Path tmpSmt = Files .createTempFile ("SMT_key_%s" .formatted (data .name ), ".smt2" );
@@ -172,9 +203,12 @@ void testTranslation(LoadedTestData data) throws Exception {
172203 .containsIgnoringWhitespaces (data .data .contains ().toArray (new String [0 ]));
173204 }
174205
206+ @ TestFactory
207+ Stream <DynamicTest > testZ3 () throws Exception {
208+ return data ().stream ()
209+ .map (it -> DynamicTest .dynamicTest (it .name , () -> testZ3 (it )));
210+ }
175211
176- @ ParameterizedTest
177- @ MethodSource ("data" )
178212 void testZ3 (LoadedTestData data ) throws Exception {
179213 SmtTestUtils .assumeZ3Installed ();
180214 Assumptions .assumeTrue (Z3_SOLVER != null );
0 commit comments