Skip to content

Commit

Permalink
Snapshot tests for JSON input
Browse files Browse the repository at this point in the history
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
  • Loading branch information
VLanvin authored and facebook-github-bot committed Nov 2, 2022
1 parent ff54eb5 commit fc7977c
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 33 deletions.
63 changes: 63 additions & 0 deletions mini-elp/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions mini-elp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ serde_json = "1.0.85"
smol_str = "0.1.21"
stdx = {git = "https://github.com/rust-analyzer/rust-analyzer", rev = "2022-09-05"}
tempfile = "3.3.0"
test-case = "2.2.1"
test-env-helpers = { git = "https://github.com/perehonchuk/test-env-helpers" }
timeout-readwrite = "0.3.2"
text-size = "1.1.0"
vfs = {git = "https://github.com/rust-analyzer/rust-analyzer", rev = "2022-09-05"}
Expand Down
2 changes: 2 additions & 0 deletions mini-elp/crates/elp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ jemallocator.workspace = true

[dev-dependencies]
expect-test.workspace = true
test-case.workspace = true
test-env-helpers.workspace = true
70 changes: 37 additions & 33 deletions mini-elp/crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ mod tests {
use expect_test::expect_file;
use expect_test::ExpectFile;
use tempfile::Builder;
use test_case::test_case;

use super::*;

Expand Down Expand Up @@ -195,55 +196,47 @@ mod tests {
eqwalize_snapshot("parse_error", "parse_error_a", false).unwrap();
}

#[test]
fn eqwalize_module_diagnostics_match_snapshot_jsonl() {
#[test_case(false ; "rebar")]
#[test_case(true ; "JSON")]
fn eqwalize_module_diagnostics_match_snapshot_jsonl(json_config: bool) {
simple_snapshot(
args_vec![
"eqwalize",
"app_a_mod2",
"--project",
"../../test_projects/standard",
"--format",
"json"
],
args_vec!["eqwalize", "app_a_mod2", "--format", "json"],
expect_file!["../resources/test/standard/eqwalize_app_a_mod2_diagnostics.jsonl"],
json_config,
"../../test_projects/standard".into(),
);
}

#[test]
fn eqwalize_module_diagnostics_match_snapshot_json_lsp() {
#[test_case(false ; "rebar")]
#[test_case(true ; "JSON")]
fn eqwalize_module_diagnostics_match_snapshot_json_lsp(json_config: bool) {
simple_snapshot(
args_vec![
"eqwalize",
"app_a_mod2",
"--project",
"../../test_projects/standard",
"--format",
"json-lsp"
],
args_vec!["eqwalize", "app_a_mod2", "--format", "json-lsp"],
expect_file!["../resources/test/standard/eqwalize_app_a_mod2_diagnostics_lsp.jsonl"],
json_config,
"../../test_projects/standard".into(),
);
}

#[test]
fn eqwalize_all_diagnostics_match_snapshot_jsonl() {
#[test_case(false ; "rebar")]
#[test_case(true ; "JSON")]
fn eqwalize_all_diagnostics_match_snapshot_jsonl(json_config: bool) {
simple_snapshot(
args_vec![
"eqwalize-all",
"--project",
"../../test_projects/standard",
"--format",
"json"
],
args_vec!["eqwalize-all", "--format", "json"],
expect_file!["../resources/test/standard/eqwalize_all_diagnostics.jsonl"],
json_config,
"../../test_projects/standard".into(),
);
}

#[test]
fn eqwalize_all_diagnostics_match_snapshot_pretty() {
#[test_case(false ; "rebar")]
#[test_case(true ; "JSON")]
fn eqwalize_all_diagnostics_match_snapshot_pretty(json_config: bool) {
simple_snapshot(
args_vec!["eqwalize-all", "--project", "../../test_projects/standard"],
args_vec!["eqwalize-all"],
expect_file!["../resources/test/standard/eqwalize_all_diagnostics.pretty"],
json_config,
"../../test_projects/standard".into(),
);
}

Expand All @@ -264,7 +257,18 @@ mod tests {
)
}

fn simple_snapshot(args: Vec<OsString>, expected: ExpectFile) {
fn simple_snapshot(
args: Vec<OsString>,
expected: ExpectFile,
json_config: bool,
project: PathBuf,
) {
let project_path = if json_config {
project.join("build_info.json")
} else {
project
};
let args = [args, args_vec!["--project", project_path]].concat();
let (stdout, stderr, code) = elp(args);
assert_eq!(
code, 0,
Expand Down
31 changes: 31 additions & 0 deletions mini-elp/test_projects/standard/build_info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"apps": [
{
"name": "app_a",
"dir": "app_a",
"ebin": "../_build/test/lib/app_a/ebin",
"extra_src_dirs": ["test"],
"include_dirs": ["include"],
"macros": ["TEST"],
"src_dirs": ["src"]
},
{
"name": "app_b",
"dir": "app_b",
"ebin": "../_build/test/lib/app_b/ebin",
"macros": ["TEST"],
"src_dirs": ["src"]
},
{
"name": "eqwalizer",
"dir": "eqwalizer",
"ebin": "../_build/test/lib/eqwalizer/ebin",
"macros": ["TEST"],
"src_dirs": ["src"]
}
],
"deps": [

],
"root": ""
}

0 comments on commit fc7977c

Please sign in to comment.