Skip to content

Commit 0a1f82c

Browse files
robertoaloimeta-codesync[bot]
authored andcommitted
Introduce simple_snapshot_output_contains helper, fix failing testcase
Summary: The testcase was not using the `simple_*` helpers, causing it to run with a buck2 config on GitHub. Buck2 is not yet configured there, causing the test to fail. Introduce a new helper that a testcase to match on the output, rather than having a completely deterministic output (memory can vary). By using the helper, apply the same filtering on the buck feature as in the other tests. Reviewed By: alanz Differential Revision: D84498544 fbshipit-source-id: 6cd58f05914cfa218496280c0e4331c2f162980a
1 parent 55a4aa6 commit 0a1f82c

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed

crates/elp/src/bin/main.rs

Lines changed: 48 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -815,43 +815,22 @@ mod tests {
815815
);
816816
}
817817

818-
#[test]
819-
fn parse_elp_report_system_stats() {
820-
let (args, _path) = add_project(
818+
#[test_case(false ; "rebar")]
819+
#[test_case(true ; "buck")]
820+
fn parse_elp_report_system_stats(buck: bool) {
821+
simple_snapshot_output_contains(
821822
args_vec!["parse-elp", "--report-system-stats", "--module", "app_a"],
822823
"standard",
824+
&[
825+
"Memory usage:",
826+
"allocated:",
827+
"active:",
828+
"resident:",
829+
"FileTextQuery",
830+
],
831+
buck,
823832
None,
824-
None,
825-
);
826-
let (stdout, stderr, code) = elp(args);
827-
828-
// Should succeed with no errors
829-
assert_eq!(
830-
code, 0,
831-
"Expected success, got code {code}\nstdout:\n{stdout}\nstderr:\n{stderr}"
832-
);
833-
assert!(stderr.is_empty(), "Expected empty stderr, got:\n{stderr}");
834-
835-
// Should contain memory usage information in stdout
836-
assert!(
837-
stdout.contains("Memory usage:"),
838-
"Expected memory usage output in stdout:\n{stdout}"
839-
);
840-
assert!(
841-
stdout.contains("allocated:"),
842-
"Expected allocated memory info in stdout:\n{stdout}"
843-
);
844-
assert!(
845-
stdout.contains("active:"),
846-
"Expected active memory info in stdout:\n{stdout}"
847-
);
848-
assert!(
849-
stdout.contains("resident:"),
850-
"Expected resident memory info in stdout:\n{stdout}"
851-
);
852-
assert!(
853-
stdout.contains("FileTextQuery"),
854-
"Expected FileTextQuery info in stdout:\n{stdout}"
833+
0,
855834
);
856835
}
857836

@@ -2420,6 +2399,41 @@ mod tests {
24202399
}
24212400
}
24222401

2402+
#[track_caller]
2403+
fn simple_snapshot_output_contains(
2404+
args: Vec<OsString>,
2405+
project: &str,
2406+
expected_patterns: &[&str],
2407+
buck: bool,
2408+
file: Option<&str>,
2409+
expected_code: i32,
2410+
) {
2411+
if !buck || cfg!(feature = "buck") {
2412+
let (mut args, _path) = add_project(args, project, file, None);
2413+
if !buck {
2414+
args.push("--rebar".into());
2415+
}
2416+
let (stdout, stderr, code) = elp(args);
2417+
assert_eq!(
2418+
code, expected_code,
2419+
"Expected exit code {expected_code}, got: {code}\nstdout:\n{stdout}\nstderr:\n{stderr}"
2420+
);
2421+
2422+
if expected_code == 0 {
2423+
assert!(stderr.is_empty(), "Expected empty stderr, got:\n{stderr}");
2424+
}
2425+
2426+
for pattern in expected_patterns {
2427+
assert!(
2428+
stdout.contains(pattern),
2429+
"Expected stdout to contain '{}', but got:\n{}",
2430+
pattern,
2431+
stdout
2432+
);
2433+
}
2434+
}
2435+
}
2436+
24232437
#[allow(clippy::too_many_arguments)]
24242438
fn check_lint_fix(
24252439
args: Vec<OsString>,

0 commit comments

Comments
 (0)