Skip to content

Commit

Permalink
Merge pull request #786 from tweag/nb/coverage_test
Browse files Browse the repository at this point in the history
Reinstate coverage tests
  • Loading branch information
nbacquey authored Oct 30, 2024
2 parents c595340 + 2f7fefe commit f2985f6
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This name should be decided amongst the team before the release.

### Added
- [#785](https://github.com/tweag/topiary/pull/785) Added the `coverage` command, that checks how much of the query file is used by the input.
- [#786](https://github.com/tweag/topiary/pull/786) Re-introduce tests to check that all of the language queries are useful.

### Changed
- [#780](https://github.com/tweag/topiary/pull/780) Measuring scopes are now independent from captures order
Expand Down
56 changes: 56 additions & 0 deletions topiary-cli/tests/sample-tester.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ fn io_test(file: &str) {
pretty_assert_eq(&expected_output, &formatted);
}

fn coverage_test(file: &str) {
let input = PathBuf::from(format!("tests/samples/input/{file}"));

// Make sure our test makes sense
assert!(input.exists());

// Run `topiary coverage` against the input file
let mut topiary = Command::cargo_bin("topiary").unwrap();
let output = topiary
.env("TOPIARY_LANGUAGE_DIR", "../topiary-queries/queries/")
.arg("coverage")
.arg(&input)
.output()
.expect("Failed to run `topiary coverage`");

if !output.status.success() {
let output_str = String::from_utf8(output.stdout).expect("Failed to decode topiary output");
panic!("Insufficient coverage of \"{file}\":\n{output_str}")
}
}

#[test]
fn input_output_tester() {
// TODO There's probably a better way than this...
Expand Down Expand Up @@ -71,6 +92,41 @@ fn input_output_tester() {
io_test("tree_sitter_query.scm");
}

#[test]
fn coverage_tester() {
// TODO There definitely should be a better way than this...

#[cfg(feature = "bash")]
coverage_test("bash.sh");

#[cfg(feature = "css")]
coverage_test("css.css");

#[cfg(feature = "json")]
coverage_test("json.json");

#[cfg(feature = "nickel")]
coverage_test("nickel.ncl");

#[cfg(feature = "ocaml")]
coverage_test("ocaml.ml");

// "ocaml-interface.mli" is voluntarily omitted:
// the queries should all be covered by "ocaml.ml"

#[cfg(feature = "ocamllex")]
coverage_test("ocamllex.mll");

#[cfg(feature = "rust")]
coverage_test("rust.rs");

#[cfg(feature = "toml")]
coverage_test("toml.toml");

#[cfg(feature = "tree_sitter_query")]
coverage_test("tree_sitter_query.scm");
}

// Test that our query files are properly formatted
#[test]
#[cfg(feature = "tree_sitter_query")]
Expand Down
35 changes: 35 additions & 0 deletions topiary-cli/tests/samples/expected/css.css
Original file line number Diff line number Diff line change
Expand Up @@ -4904,3 +4904,38 @@
display: none !important;
}
}
@media (min-width: 1200px), (max-width: 1200px) and (not (min-width: 1200px)) {
.fs-1 {
font-size: 2.5rem !important;
}
}
@import url("my-imported-styles.css");
@charset "UTF-8";
@keyframes identifier {
0% {
top: 0;
left: 0;
}
30% {
top: 50px;
}
72% {
left: 50px;
}
100% {
top: 100px;
left: 100%;
}
}
/* Various selectors: descendant, sibling, and adjacent sibling */
li li {
list-style-type: circle;
}

li ~ li {
list-style-type: circle;
}

li + li {
list-style-type: circle;
}
35 changes: 35 additions & 0 deletions topiary-cli/tests/samples/input/css.css

Large diffs are not rendered by default.

0 comments on commit f2985f6

Please sign in to comment.