Skip to content

Commit 8a173e0

Browse files
committed
Single files instead of one large files
1 parent 08dfd6e commit 8a173e0

30 files changed

+344
-521
lines changed

key.core/src/test/java/de/uka/ilkd/key/scripts/TestProofScriptCommand.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
* SPDX-License-Identifier: GPL-2.0-only */
44
package de.uka.ilkd.key.scripts;
55

6-
import java.io.FileNotFoundException;
6+
import java.io.File;
77
import java.io.IOException;
8-
import java.net.URI;
98
import java.net.URISyntaxException;
10-
import java.net.URL;
119
import java.nio.file.Files;
1210
import java.nio.file.Path;
13-
import java.util.Arrays;
11+
import java.nio.file.Paths;
12+
import java.util.ArrayList;
1413
import java.util.List;
1514

1615
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
@@ -34,32 +33,42 @@
3433
import static org.assertj.core.api.Assertions.assertThat;
3534
import static org.junit.jupiter.api.Assertions.assertTrue;
3635

37-
3836
/**
3937
* see {@link MasterHandlerTest} from where I copied quite a bit.
4038
*/
4139
public class TestProofScriptCommand {
42-
public record TestInstance(String name, String key, String script, String exception,
40+
public record TestInstance(String key, String script, String exception,
4341
String[] goals, Integer selectedGoal) {
4442
}
4543

46-
4744
public static List<Arguments> data() throws IOException, URISyntaxException {
48-
URL url = TestProofScriptCommand.class.getResource("cases.yml");
49-
if (url == null) {
50-
throw new FileNotFoundException("Cannot find resource 'cases'.");
45+
var folder = Paths.get("src/test/resources/de/uka/ilkd/key/macros/scripts");
46+
try (var walker = Files.walk(folder)) {
47+
List<Path> files =
48+
walker.filter(it -> it.getFileName().toString().endsWith(".yml")).toList();
49+
var objectMapper = new ObjectMapper(new YAMLFactory());
50+
objectMapper.findAndRegisterModules();
51+
52+
List<Arguments> args = new ArrayList(files.size());
53+
for (Path path : files) {
54+
try {
55+
TestInstance instance =
56+
objectMapper.readValue(path.toFile(), TestInstance.class);
57+
args.add(Arguments.of(path.toFile(), instance));
58+
} catch (Exception e) {
59+
System.out.println(path);
60+
e.printStackTrace();
61+
throw e;
62+
}
63+
}
64+
return args;
5165
}
52-
53-
var objectMapper = new ObjectMapper(new YAMLFactory());
54-
objectMapper.findAndRegisterModules();
55-
TestInstance[] instances = objectMapper.readValue(url, TestInstance[].class);
56-
return Arrays.stream(instances).map(Arguments::of).toList();
5766
}
5867

5968
@ParameterizedTest
6069
@MethodSource("data")
61-
void testProofScript(TestInstance data) throws Exception {
62-
var name = data.name();
70+
void testProofScript(File file, TestInstance data) throws Exception {
71+
var name = file.getName().replace(".yml", "");
6372
Path tmpKey = Files.createTempFile("proofscript_key_" + name, ".key");
6473
Files.writeString(tmpKey, data.key());
6574

key.core/src/test/java/de/uka/ilkd/key/smt/newsmt2/MasterHandlerTest.java

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
import java.nio.charset.StandardCharsets;
1111
import java.nio.file.Files;
1212
import java.nio.file.Path;
13+
import java.nio.file.Paths;
1314
import java.util.*;
1415
import java.nio.file.Paths;
1516
import java.util.ArrayList;
1617
import java.util.List;
1718
import java.util.Properties;
19+
import java.util.stream.Stream;
1820

1921
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
2022
import de.uka.ilkd.key.control.KeYEnvironment;
@@ -31,16 +33,14 @@
3133
import org.key_project.prover.sequent.Sequent;
3234
import org.key_project.util.Streams;
3335

34-
import com.fasterxml.jackson.core.type.TypeReference;
3536
import com.fasterxml.jackson.databind.ObjectMapper;
3637
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
3738
import org.assertj.core.api.Assertions;
3839
import org.jspecify.annotations.NonNull;
3940
import org.jspecify.annotations.Nullable;
4041
import 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;
4444
import org.slf4j.Logger;
4545
import org.slf4j.LoggerFactory;
4646

@@ -56,10 +56,13 @@
5656
*/
5757
public 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);

key.core/src/test/resources/de/uka/ilkd/key/scripts/cases.yml

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)