Skip to content

Commit 23a566f

Browse files
committed
Single files instead of one large files
1 parent 678f683 commit 23a566f

38 files changed

+455
-501
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

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

Lines changed: 27 additions & 18 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.macros.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;
@@ -33,32 +32,42 @@
3332
import static org.assertj.core.api.Assertions.assertThat;
3433
import static org.junit.jupiter.api.Assertions.assertTrue;
3534

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

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

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

@@ -67,7 +76,7 @@ void testProofScript(TestInstance data) throws Exception {
6776
Proof proof = env.getLoadedProof();
6877

6978
ProofScriptEngine pse = new ProofScriptEngine(data.script(),
70-
new Location(URI.create("file:/"+data.name), Position.newOneBased(1, 1)));
79+
new Location(file.toURI(), Position.newOneBased(1, 1)));
7180

7281
boolean hasException = data.exception() != null;
7382
try {

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.nio.charset.StandardCharsets;
1010
import java.nio.file.Files;
1111
import java.nio.file.Path;
12+
import java.nio.file.Paths;
1213
import java.util.*;
1314

1415
import de.uka.ilkd.key.control.DefaultUserInterfaceControl;
@@ -25,7 +26,6 @@
2526

2627
import org.key_project.util.Streams;
2728

28-
import com.fasterxml.jackson.core.type.TypeReference;
2929
import com.fasterxml.jackson.databind.ObjectMapper;
3030
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
3131
import org.assertj.core.api.Assertions;
@@ -67,43 +67,50 @@ public class MasterHandlerTest {
6767

6868
public static List<Arguments> data()
6969
throws IOException, URISyntaxException, ProblemLoaderException {
70-
try (var input = MasterHandlerTest.class.getResourceAsStream("cases.yml")) {
71-
var om = new ObjectMapper(new YAMLFactory());
72-
TypeReference<HashMap<String, TestData>> typeRef = new TypeReference<>() {
73-
};
74-
Map<String, TestData> preData = om.readValue(input, typeRef);
75-
var result = new ArrayList<Arguments>(preData.size());
76-
for (var entry : preData.entrySet()) {
77-
final var value = entry.getValue();
70+
var om = new ObjectMapper(new YAMLFactory());
71+
var path = Paths.get("src/test/resources/de/uka/ilkd/key/smt/newsmt2/cases/");
72+
try (var walker = Files.walk(path)) {
73+
var files = walker.filter(it -> it.getFileName().endsWith("yml")).toList();
74+
var result = new ArrayList<Arguments>(files.size());
75+
for (Path pFile : files) {
76+
var file = pFile.toFile();
77+
78+
TestData value = om.readValue(file, TestData.class);
7879

7980
if (value.state == TestDataState.IGNORE) {
80-
LOGGER.info("Test {} case has been marked ignore", entry.getKey());
81+
LOGGER.info("Test {} case has been marked ignore", file);
8182
continue;
8283
}
83-
84-
final var testData = value.load(entry.getKey());
84+
final var testData = value.load(file.getName().replace(".yml", ""));
8585
result.add(Arguments.of(testData));
8686
}
8787
return result;
8888
}
8989
}
9090

91+
/**
92+
* Describes the state of a test instance.
93+
*/
9194
public enum TestDataState {
9295
EMPTY, EXTENDED, IGNORE
9396
}
9497

98+
/**
99+
* Expected outcome of a test instance.
100+
*/
95101
public enum Expectation {
96102
VALID, FAIL, IRRELEVANT
97103
}
98104

99105
/**
100106
* This class contains the information about the test fixtures that is loaded via the YAML.
101-
* @param contains a list of strings that are expected in the SMT translation
107+
*
108+
* @param contains a list of strings that are expected in the SMT translation
102109
* @param smtSettings required key/values in the smt settings.
103-
* @param expected expected output of Z3
104-
* @param state state of the test
105-
* @param javaSrc path to necessary java sources
106-
* @param keySrc contents of the key file to be loaded.
110+
* @param expected expected output of Z3
111+
* @param state state of the test
112+
* @param javaSrc path to necessary java sources
113+
* @param keySrc contents of the key file to be loaded.
107114
*/
108115
public record TestData(List<String> contains,
109116
Properties smtSettings,
@@ -119,7 +126,7 @@ private LoadedTestData load(String name) throws IOException, ProblemLoaderExcept
119126
Path srcDir = Files.createTempDirectory("SMT_key_" + name);
120127
Path tmpSrc = srcDir.resolve("src.java");
121128
Files.writeString(tmpSrc, javaSrc);
122-
keySrc += "\n\\javaSource \"%s\";\n".formatted(srcDir);
129+
keySrc += "\n/javaSource \"%s\";\n".formatted(srcDir);
123130
}
124131

125132
Path tmpKey = Files.createTempFile("SMT_key_%s".formatted(name), ".key");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
key: |
2+
\predicates { a; b; }
3+
\problem { a & b }
4+
script: |
5+
rule andRight;
6+
goals:
7+
- ==> b
8+
- ==> a

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

Lines changed: 0 additions & 90 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
key: |
2+
\predicates { a; b; c; d; e; f; }
3+
\problem { a -> b }
4+
script: |
5+
macro split-prop;
6+
hide "b ==>";
7+
exception: |2
8+
9+
Error while executing script: This formula is not on the sequent: b
10+
11+
Command: hide "b ==>";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
key: |
2+
\predicates { a; b; c; d; e; f; }
3+
4+
\problem { a & b & c -> d | e | f }
5+
script: |
6+
macro split-prop;
7+
hide "a ==> d, e";
8+
goals:
9+
- "b, c ==> f"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
key: |
2+
\predicates { a; b; }
3+
\problem { a & b }
4+
script: |
5+
rule andLeft;
6+
exception: |
7+
Error while executing script: No matching applications.
8+
9+
Command: rule andLeft;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
key: |
2+
\predicates { a; b; c; }
3+
\problem { a & b & c}
4+
script: |
5+
macro split-prop;
6+
select formula="b";
7+
goals:
8+
- ==> b
9+
- ==> a
10+
- ==> c
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
key: |
2+
\problem { 2=3 -> 3=4 }
3+
script: |
4+
rule impRight;
5+
hide "2=3 ==> 3=4";
6+
unhide "2=3 ==>";
7+
unhide "==> 3=4";
8+
goals:
9+
- 2 = 3 ==> 3 = 4

0 commit comments

Comments
 (0)