Skip to content

Commit

Permalink
Allow test suites to run to be specified on the command line.
Browse files Browse the repository at this point in the history
Issue #16 - Allow the test suites to run to be provided as command line
arguments. Any number of suites can be provided, any unknown test
suite names are ignored.
  • Loading branch information
lkitching committed Oct 19, 2018
1 parent ee5fa65 commit 5badc76
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion src/rdf_validator/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
12 changes: 10 additions & 2 deletions src/rdf_validator/test_cases.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
17 changes: 17 additions & 0 deletions test/rdf_validator/test_cases_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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 [])))))))

0 comments on commit 5badc76

Please sign in to comment.