diff --git a/README.md b/README.md index b02274b..4671b6c 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,27 @@ this is valid as long as `suite1.edn` is provided as a suite whenever `suite2.ed java -jar rdf-validator-standalone.jar --endpoint data.ttl --suite suite1.edn --suite suite2.edn +### Running individual suites + +By default all test cases within all test suites will be executed when running `rdf-validator`. +This may be undesirable if many test suites are defined, or if one suite imports from another since +this will cause imported test cases to be executed multiple times. + +Individual test suites can be executed by providing the suite names to be run in an argument list +to the command-line invocation e.g. + +#### tests.edn +```clojure +{:suite1 ["test1.sparql" "test2.sparql" "test3.sparql"] + :suite2 {:import [:suite1] + :exclude [:suite1/test2] + :tests ["test4.sparql"] + :suite3 ["test5.sparql"]} +``` + + java -jar rdf-validator-standalone.jar --endpoint data.ttl --suite tests.edn suite2 suite3 + +This will execute the tests defined within `suite2` and `suite3` within `tests.edn`. ## License diff --git a/src/rdf_validator/core.clj b/src/rdf_validator/core.clj index e2db06d..12c1917 100644 --- a/src/rdf_validator/core.clj +++ b/src/rdf_validator/core.clj @@ -117,7 +117,8 @@ endpoint (create-endpoint options) query-variables (:variables options) suites (tc/resolve-test-suites suite-files) - test-cases (tc/suite-tests suites) + suites-to-run (:arguments result) + test-cases (tc/suite-tests suites suites-to-run) test-reporter (reporting/->ConsoleTestReporter) {:keys [failed errored] :as test-summary} (run-test-cases test-cases query-variables endpoint test-reporter)] (System/exit (+ failed errored))) diff --git a/src/rdf_validator/test_cases.clj b/src/rdf_validator/test_cases.clj index b3047b0..c642894 100644 --- a/src/rdf_validator/test_cases.clj +++ b/src/rdf_validator/test_cases.clj @@ -205,5 +205,13 @@ test-suite-files)] (resolve-imports raw))) -(defn suite-tests [suite] - (mapcat :tests (vals suite))) +(defn suite-tests + "Given a test suite map and a collection of test suite names to run, returns a sequence of test cases to be executed. + If no suite names are specified, all tests for all suites are returned." + [suites to-run-names] + (let [get-suite (fn [suite-name] + (get suites (keyword suite-name))) + suites-to-run (if (seq to-run-names) + (map get-suite to-run-names) + (vals suites))] + (mapcat :tests suites-to-run))) diff --git a/test/rdf_validator/test_cases_test.clj b/test/rdf_validator/test_cases_test.clj index 32a966d..c58c445 100644 --- a/test/rdf_validator/test_cases_test.clj +++ b/test/rdf_validator/test_cases_test.clj @@ -165,3 +165,20 @@ :suite :imports :name "ask_resource"}]}}] (is (= expected (resolve-test-suites suite-files))))) + +(deftest suite-tests-test + (let [test1 {:name "test1"} + test2 {:name "test2"} + test3 {:name "test3"} + test4 {:name "test4"} + suites {:suite1 {:tests [test1 test2]} + :suite2 {:tests [test3]} + :suite3 {:tests [test4]}}] + (testing "specified suites" + (let [to-run-names ["suite1" "suite3" "missing"] + to-run (suite-tests suites to-run-names)] + (is (= #{test1 test2 test4} (set to-run))))) + + (testing "all suites" + (is (= #{test1 test2 test3 test4} + (set (suite-tests suites [])))))))