Skip to content

Commit fc7977c

Browse files
VLanvinfacebook-github-bot
authored andcommitted
Snapshot tests for JSON input
Summary: Adapted existing snapshot tests to also support json input, see file `test_projects/standard/build_info.json`. Reviewed By: ilya-klyuchnikov Differential Revision: D40837664 fbshipit-source-id: 4e829cb81e5613afab84bb07d14be768241b1eb1
1 parent ff54eb5 commit fc7977c

File tree

5 files changed

+135
-33
lines changed

5 files changed

+135
-33
lines changed

mini-elp/Cargo.lock

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

mini-elp/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ serde_json = "1.0.85"
3030
smol_str = "0.1.21"
3131
stdx = {git = "https://github.com/rust-analyzer/rust-analyzer", rev = "2022-09-05"}
3232
tempfile = "3.3.0"
33+
test-case = "2.2.1"
34+
test-env-helpers = { git = "https://github.com/perehonchuk/test-env-helpers" }
3335
timeout-readwrite = "0.3.2"
3436
text-size = "1.1.0"
3537
vfs = {git = "https://github.com/rust-analyzer/rust-analyzer", rev = "2022-09-05"}

mini-elp/crates/elp/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ jemallocator.workspace = true
4040

4141
[dev-dependencies]
4242
expect-test.workspace = true
43+
test-case.workspace = true
44+
test-env-helpers.workspace = true

mini-elp/crates/elp/src/bin/main.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ mod tests {
8282
use expect_test::expect_file;
8383
use expect_test::ExpectFile;
8484
use tempfile::Builder;
85+
use test_case::test_case;
8586

8687
use super::*;
8788

@@ -195,55 +196,47 @@ mod tests {
195196
eqwalize_snapshot("parse_error", "parse_error_a", false).unwrap();
196197
}
197198

198-
#[test]
199-
fn eqwalize_module_diagnostics_match_snapshot_jsonl() {
199+
#[test_case(false ; "rebar")]
200+
#[test_case(true ; "JSON")]
201+
fn eqwalize_module_diagnostics_match_snapshot_jsonl(json_config: bool) {
200202
simple_snapshot(
201-
args_vec![
202-
"eqwalize",
203-
"app_a_mod2",
204-
"--project",
205-
"../../test_projects/standard",
206-
"--format",
207-
"json"
208-
],
203+
args_vec!["eqwalize", "app_a_mod2", "--format", "json"],
209204
expect_file!["../resources/test/standard/eqwalize_app_a_mod2_diagnostics.jsonl"],
205+
json_config,
206+
"../../test_projects/standard".into(),
210207
);
211208
}
212209

213-
#[test]
214-
fn eqwalize_module_diagnostics_match_snapshot_json_lsp() {
210+
#[test_case(false ; "rebar")]
211+
#[test_case(true ; "JSON")]
212+
fn eqwalize_module_diagnostics_match_snapshot_json_lsp(json_config: bool) {
215213
simple_snapshot(
216-
args_vec![
217-
"eqwalize",
218-
"app_a_mod2",
219-
"--project",
220-
"../../test_projects/standard",
221-
"--format",
222-
"json-lsp"
223-
],
214+
args_vec!["eqwalize", "app_a_mod2", "--format", "json-lsp"],
224215
expect_file!["../resources/test/standard/eqwalize_app_a_mod2_diagnostics_lsp.jsonl"],
216+
json_config,
217+
"../../test_projects/standard".into(),
225218
);
226219
}
227220

228-
#[test]
229-
fn eqwalize_all_diagnostics_match_snapshot_jsonl() {
221+
#[test_case(false ; "rebar")]
222+
#[test_case(true ; "JSON")]
223+
fn eqwalize_all_diagnostics_match_snapshot_jsonl(json_config: bool) {
230224
simple_snapshot(
231-
args_vec![
232-
"eqwalize-all",
233-
"--project",
234-
"../../test_projects/standard",
235-
"--format",
236-
"json"
237-
],
225+
args_vec!["eqwalize-all", "--format", "json"],
238226
expect_file!["../resources/test/standard/eqwalize_all_diagnostics.jsonl"],
227+
json_config,
228+
"../../test_projects/standard".into(),
239229
);
240230
}
241231

242-
#[test]
243-
fn eqwalize_all_diagnostics_match_snapshot_pretty() {
232+
#[test_case(false ; "rebar")]
233+
#[test_case(true ; "JSON")]
234+
fn eqwalize_all_diagnostics_match_snapshot_pretty(json_config: bool) {
244235
simple_snapshot(
245-
args_vec!["eqwalize-all", "--project", "../../test_projects/standard"],
236+
args_vec!["eqwalize-all"],
246237
expect_file!["../resources/test/standard/eqwalize_all_diagnostics.pretty"],
238+
json_config,
239+
"../../test_projects/standard".into(),
247240
);
248241
}
249242

@@ -264,7 +257,18 @@ mod tests {
264257
)
265258
}
266259

267-
fn simple_snapshot(args: Vec<OsString>, expected: ExpectFile) {
260+
fn simple_snapshot(
261+
args: Vec<OsString>,
262+
expected: ExpectFile,
263+
json_config: bool,
264+
project: PathBuf,
265+
) {
266+
let project_path = if json_config {
267+
project.join("build_info.json")
268+
} else {
269+
project
270+
};
271+
let args = [args, args_vec!["--project", project_path]].concat();
268272
let (stdout, stderr, code) = elp(args);
269273
assert_eq!(
270274
code, 0,
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"apps": [
3+
{
4+
"name": "app_a",
5+
"dir": "app_a",
6+
"ebin": "../_build/test/lib/app_a/ebin",
7+
"extra_src_dirs": ["test"],
8+
"include_dirs": ["include"],
9+
"macros": ["TEST"],
10+
"src_dirs": ["src"]
11+
},
12+
{
13+
"name": "app_b",
14+
"dir": "app_b",
15+
"ebin": "../_build/test/lib/app_b/ebin",
16+
"macros": ["TEST"],
17+
"src_dirs": ["src"]
18+
},
19+
{
20+
"name": "eqwalizer",
21+
"dir": "eqwalizer",
22+
"ebin": "../_build/test/lib/eqwalizer/ebin",
23+
"macros": ["TEST"],
24+
"src_dirs": ["src"]
25+
}
26+
],
27+
"deps": [
28+
29+
],
30+
"root": ""
31+
}

0 commit comments

Comments
 (0)