Skip to content

Commit 6d729a1

Browse files
authored
Use insta for the integration tests (mozilla#967)
* Make sure the submodules are populated before running cargo test * Remove rust std from the tests * Use insta * Add a rust integration test using serde sources * Change the snapshots layout And omit the FuncSpace::name * Remove excess whitespace from the names
1 parent d6b8e9e commit 6d729a1

File tree

10 files changed

+106
-155
lines changed

10 files changed

+106
-155
lines changed

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
[submodule "tests/repositories/DeepSpeech"]
55
path = tests/repositories/DeepSpeech
66
url = https://github.com/mozilla/DeepSpeech
7-
[submodule "tests/repositories/rust"]
8-
path = tests/repositories/rust
9-
url = https://github.com/rust-lang/rust.git
107
[submodule "tests/repositories/pdf.js"]
118
path = tests/repositories/pdf.js
129
url = https://github.com/mozilla/pdf.js
10+
[submodule "tests/repositories/serde"]
11+
path = tests/repositories/serde
12+
url = https://github.com/serde-rs/serde

.taskcluster.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ tasks:
4747
git clone --quiet ${repository} &&
4848
cd rust-code-analysis &&
4949
git -c advice.detachedHead=false checkout ${head_rev} &&
50+
git submodule update --init &&
5051
pip3 install --quiet pre-commit &&
5152
pre-commit run -a --show-diff-on-failure &&
5253
pre-commit run --show-diff-on-failure -c .pre-commit-audit-config.yaml &&
@@ -113,6 +114,7 @@ tasks:
113114
git clone --quiet ${repository} &&
114115
cd rust-code-analysis &&
115116
git -c advice.detachedHead=false checkout ${head_rev} &&
117+
git submodule update --init &&
116118
cargo test --workspace --verbose --all-features --target x86_64-unknown-linux-gnu &&
117119
../grcov . --binary-path ./target/ -s . -t lcov --llvm --branch --ignore-not-existing --ignore '/*' -o lcov.info &&
118120
bash <(curl -s https://codecov.io/bash) -f lcov.info"
@@ -143,6 +145,7 @@ tasks:
143145
- git clone --quiet ${repository}
144146
- cd rust-code-analysis
145147
- git -c advice.detachedHead=false checkout ${head_rev}
148+
- git submodule update --init
146149
- cargo test --workspace --verbose --all-features
147150
mounts:
148151
- content:

Cargo.lock

Lines changed: 52 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,14 @@ tree-sitter-mozcpp = { path = "./tree-sitter-mozcpp", version = "=0.20.1" }
3939
tree-sitter-mozjs = { path = "./tree-sitter-mozjs", version = "=0.19.0" }
4040

4141
[dev-dependencies]
42+
insta = { version = "1.22.0", features = ["yaml"] }
4243
pretty_assertions = "^1.0"
43-
serde_json = { version = "^1.0", features = ["arbitrary_precision"] }
44+
45+
[profile.dev.package.insta]
46+
opt-level = 3
47+
48+
[profile.dev.package.similar]
49+
opt-level = 3
4450

4551
[workspace]
4652
members = ["rust-code-analysis-cli", "rust-code-analysis-web"]

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ To verify whether all tests pass, run the `cargo test` command.
7171
cargo test --workspace --all-features --verbose
7272
```
7373

74+
### Updating insta tests
75+
We use [insta](https://insta.rs), to update the snapshot tests you should install [cargo insta](https://crates.io/crates/cargo-insta)
76+
77+
``` console
78+
cargo insta test --review
79+
```
80+
81+
Will run the tests, generate the new snapshot references and let you review them.
82+
7483
# Contributing
7584

7685
If you want to contribute to the development of this software, have a look at the

src/spaces.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ impl FuncSpace {
164164
node.object().end_position().row + 1,
165165
),
166166
};
167+
167168
Self {
168-
name: T::get_func_space_name(node, code).map(|name| name.to_string()),
169+
name: T::get_func_space_name(node, code)
170+
.map(|name| name.split_whitespace().collect::<Vec<_>>().join(" ")),
169171
spaces: Vec::new(),
170172
metrics: CodeMetrics::default(),
171173
kind,

tests/repositories/rca-output

tests/repositories/rust

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/repositories/serde

Submodule serde added at d493649

0 commit comments

Comments
 (0)