Skip to content

Commit 98797cc

Browse files
committed
compat test but got failures
1 parent f2b5c95 commit 98797cc

File tree

5 files changed

+125
-12
lines changed

5 files changed

+125
-12
lines changed

json-compatibility-suite/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,28 @@
3838
<scope>test</scope>
3939
</dependency>
4040
</dependencies>
41+
42+
<build>
43+
<plugins>
44+
<plugin>
45+
<groupId>com.googlecode.maven-download-plugin</groupId>
46+
<artifactId>download-maven-plugin</artifactId>
47+
<executions>
48+
<execution>
49+
<id>download-json-test-suite</id>
50+
<phase>generate-test-resources</phase>
51+
<goals>
52+
<goal>wget</goal>
53+
</goals>
54+
<configuration>
55+
<url>https://github.com/nst/JSONTestSuite/archive/refs/heads/master.zip</url>
56+
<outputDirectory>${project.build.directory}/test-resources</outputDirectory>
57+
<outputFileName>json-test-suite.zip</outputFileName>
58+
<unpack>true</unpack>
59+
</configuration>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
</plugins>
64+
</build>
4165
</project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package jdk.sandbox.compatibility;
2+
3+
import org.junit.jupiter.api.Test;
4+
import java.nio.file.Files;
5+
import java.nio.file.Path;
6+
import java.nio.file.Paths;
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class DownloadVerificationTest {
10+
@Test
11+
void testSuiteDownloaded() {
12+
Path testDir = Paths.get("target/test-resources/JSONTestSuite-master/test_parsing");
13+
assertThat(testDir)
14+
.as("JSON Test Suite should be downloaded and extracted")
15+
.exists()
16+
.isDirectory();
17+
18+
// Verify some test files exist
19+
assertThat(testDir.resolve("y_structure_whitespace_array.json"))
20+
.as("Should contain valid test files")
21+
.exists();
22+
}
23+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package jdk.sandbox.compatibility;
2+
3+
import jdk.sandbox.java.util.json.Json;
4+
import jdk.sandbox.java.util.json.JsonParseException;
5+
import org.junit.jupiter.api.DynamicTest;
6+
import org.junit.jupiter.api.TestFactory;
7+
8+
import java.nio.file.Files;
9+
import java.nio.file.Path;
10+
import java.nio.file.Paths;
11+
import java.util.stream.Stream;
12+
13+
import static org.assertj.core.api.Assertions.*;
14+
15+
/**
16+
* Runs the JSON Test Suite against our implementation.
17+
* Files are categorized:
18+
* - y_*.json: Valid JSON that MUST parse successfully
19+
* - n_*.json: Invalid JSON that MUST fail to parse
20+
* - i_*.json: Implementation-defined (may accept or reject)
21+
*/
22+
public class JsonTestSuiteTest {
23+
24+
private static final Path TEST_DIR = Paths.get("target/test-resources/JSONTestSuite-master/test_parsing");
25+
26+
@TestFactory
27+
Stream<DynamicTest> runJsonTestSuite() throws Exception {
28+
if (!Files.exists(TEST_DIR)) {
29+
System.err.println("Test suite not found. Run: mvn test-compile");
30+
return Stream.empty();
31+
}
32+
33+
return Files.walk(TEST_DIR)
34+
.filter(p -> p.toString().endsWith(".json"))
35+
.sorted()
36+
.map(this::createTest);
37+
}
38+
39+
private DynamicTest createTest(Path file) {
40+
String filename = file.getFileName().toString();
41+
42+
return DynamicTest.dynamicTest(filename, () -> {
43+
String content = Files.readString(file);
44+
45+
if (filename.startsWith("y_")) {
46+
// Valid JSON - must parse successfully
47+
assertThatCode(() -> Json.parse(content))
48+
.as("File %s should parse successfully", filename)
49+
.doesNotThrowAnyException();
50+
51+
} else if (filename.startsWith("n_")) {
52+
// Invalid JSON - must fail to parse
53+
assertThatThrownBy(() -> Json.parse(content))
54+
.as("File %s should fail to parse", filename)
55+
.isInstanceOf(JsonParseException.class);
56+
57+
} else if (filename.startsWith("i_")) {
58+
// Implementation defined - just verify no crash
59+
try {
60+
Json.parse(content);
61+
// OK - we accepted it
62+
} catch (JsonParseException e) {
63+
// OK - we rejected it
64+
} catch (Exception e) {
65+
// NOT OK - unexpected exception type
66+
fail("Unexpected exception for %s: %s", filename, e);
67+
}
68+
}
69+
});
70+
}
71+
}

json-compatibility-suite/src/test/java/jdk/sandbox/testsuite/PlaceholderTest.java

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

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
5555
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
5656
<maven-install-plugin.version>3.1.2</maven-install-plugin.version>
57+
<download-maven-plugin.version>1.7.1</download-maven-plugin.version>
5758
</properties>
5859

5960

@@ -114,7 +115,12 @@
114115
<artifactId>maven-install-plugin</artifactId>
115116
<version>${maven-install-plugin.version}</version>
116117
</plugin>
118+
<plugin>
119+
<groupId>com.googlecode.maven-download-plugin</groupId>
120+
<artifactId>download-maven-plugin</artifactId>
121+
<version>${download-maven-plugin.version}</version>
122+
</plugin>
117123
</plugins>
118124
</pluginManagement>
119125
</build>
120-
</project>
126+
</project>

0 commit comments

Comments
 (0)