From ffede563c36b2303342c56f4cc7b133872084f50 Mon Sep 17 00:00:00 2001 From: Haibo Sun <105451682+Haibo-S@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:42:22 -0400 Subject: [PATCH] Clean up running conformance tests (#24) Co-authored-by: Werner Dietl --- .../NullnessJSpecifyConformanceTest.java | 76 +++++++++---------- 1 file changed, 35 insertions(+), 41 deletions(-) diff --git a/src/test/java/conformance/NullnessJSpecifyConformanceTest.java b/src/test/java/conformance/NullnessJSpecifyConformanceTest.java index 6aac5f2..29f46da 100644 --- a/src/test/java/conformance/NullnessJSpecifyConformanceTest.java +++ b/src/test/java/conformance/NullnessJSpecifyConformanceTest.java @@ -25,35 +25,45 @@ /** A class to run the conformance tests against the EISOP Checker Framework. */ public final class NullnessJSpecifyConformanceTest { - /** Directory of the JSpecify Conformance Tests. */ - private final Path testDir; - - /** Location of the report. */ - private final Path reportPath; - - /** Directory of the JSpecify Conformance Tests for samples. */ - private final Path testDirSamples; - - /** Location of the report for samples. */ - private final Path reportPathSamples; - - /** JSpecify conformance test dependencies. */ - private final ImmutableList deps; - /** Options to pass to the checker. */ private static final ImmutableList TEST_OPTIONS = ImmutableList.of("-AassumePure", "-Adetailedmsgtext"); - /** Create a NullnessJSpecifyConformanceTest. */ - public NullnessJSpecifyConformanceTest() { - this.testDir = getSystemPropertyPath("ConformanceTest.inputs"); - this.reportPath = getSystemPropertyPath("ConformanceTest.report"); - this.testDirSamples = getSystemPropertyPath("ConformanceTest.samples.inputs"); - this.reportPathSamples = getSystemPropertyPath("ConformanceTest.samples.report"); - this.deps = - Splitter.on(":").splitToList(System.getProperty("ConformanceTest.deps")).stream() - .map(dep -> Paths.get(dep)) - .collect(toImmutableList()); + + /** Run the conformance tests. */ + @Test + public void conformanceTests() throws IOException { + runConformanceTests( + "ConformanceTest.inputs", + "ConformanceTest.report", + "ConformanceTest.deps"); + } + + /** Run the conformance tests on the samples. */ + @Test + public void conformanceTestsOnSamples() throws IOException { + runConformanceTests( + "ConformanceTest.samples.inputs", + "ConformanceTest.samples.report", + null); // No deps needed for conformance samples + } + + /** + * Runs the conformance tests with the specified test directory and report path. + * + * @param testDirProperty the system property key for the test directory path + * @param reportPathProperty the system property key for the report file path + * @param depsProperty the system property key for dependencies, or null if no dependencies are required + */ + private void runConformanceTests(String testDirProperty, String reportPathProperty, String depsProperty) throws IOException { + Path testDir = getSystemPropertyPath(testDirProperty); + Path reportPath = getSystemPropertyPath(reportPathProperty); + ImmutableList deps = depsProperty != null ? + Splitter.on(":").splitToList(depsProperty).stream().map(Paths::get).collect(toImmutableList()) : + ImmutableList.of(); // for conformance samples, creates an empty immutable list + + ConformanceTestRunner runner = new ConformanceTestRunner(NullnessJSpecifyConformanceTest::analyze); + runner.checkConformance(testDir, deps, reportPath); } /** @@ -69,22 +79,6 @@ private Path getSystemPropertyPath(String propertyName) { return Paths.get(path); } - /** Run the conformance tests. */ - @Test - public void conformanceTests() throws IOException { - ConformanceTestRunner runner = - new ConformanceTestRunner(NullnessJSpecifyConformanceTest::analyze); - runner.checkConformance(testDir, deps, reportPath); - } - - /** Run the conformance tests on the samples. */ - @Test - public void conformanceTestsOnSamples() throws IOException { - ConformanceTestRunner runner = - new ConformanceTestRunner(NullnessJSpecifyConformanceTest::analyze); - runner.checkConformance(testDirSamples, deps, reportPathSamples); - } - /** * Analyze the conformance tests by comparing reported facts against expected facts. *