Skip to content

Commit 3368d51

Browse files
committed
test: 让 Zig 伪工具完整消费源码输入
1 parent dc13d15 commit 3368d51

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

‎crates/codeguard-cli/tests/zig_lint_cli.rs‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn native_zig_diagnostic_takes_priority_over_wasm_candidate() {
1616
let tool = root.join("zig-tool");
1717
fs::write(
1818
&tool,
19-
"#!/bin/sh\nif [ \"$1\" = version ]; then printf '0.16.0\\n'; exit 0; fi\nif [ \"$1\" = ast-check ]; then printf '<stdin>:1:23: error: expected closing brace\\n' >&2; exit 1; fi\nexit 2\n",
19+
"#!/bin/sh\nif [ \"$1\" = version ]; then printf '0.16.0\\n'; exit 0; fi\nif [ \"$1\" = ast-check ]; then while IFS= read -r line; do :; done; printf '<stdin>:1:23: error: expected closing brace\\n' >&2; exit 1; fi\nexit 2\n",
2020
)
2121
.unwrap();
2222
fs::set_permissions(&tool, fs::Permissions::from_mode(0o700)).unwrap();
@@ -28,7 +28,10 @@ fn native_zig_diagnostic_takes_priority_over_wasm_candidate() {
2828
.unwrap();
2929
assert_eq!(output.status.code(), Some(3));
3030
let report: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
31-
assert_eq!(report["native"]["status"], "diagnostics_observed");
31+
assert_eq!(
32+
report["native"]["status"], "diagnostics_observed",
33+
"{report}"
34+
);
3235
assert_eq!(report["native"]["diagnostic_count"], 1);
3336
assert_eq!(report["native"]["tool_sha256"].as_str().unwrap().len(), 64);
3437
assert_eq!(report["syntax_precheck"], serde_json::Value::Null);
@@ -75,7 +78,7 @@ fn clean_native_ast_check_does_not_claim_full_lint_or_run_wasm() {
7578
let tool = root.join("zig-tool");
7679
fs::write(
7780
&tool,
78-
"#!/bin/sh\nif [ \"$1\" = version ]; then printf '0.16.0\\n'; exit 0; fi\nif [ \"$1\" = ast-check ]; then exit 0; fi\nexit 2\n",
81+
"#!/bin/sh\nif [ \"$1\" = version ]; then printf '0.16.0\\n'; exit 0; fi\nif [ \"$1\" = ast-check ]; then while IFS= read -r line; do :; done; exit 0; fi\nexit 2\n",
7982
)
8083
.unwrap();
8184
fs::set_permissions(&tool, fs::Permissions::from_mode(0o700)).unwrap();
@@ -87,7 +90,7 @@ fn clean_native_ast_check_does_not_claim_full_lint_or_run_wasm() {
8790
.unwrap();
8891
assert_eq!(output.status.code(), Some(3));
8992
let report: serde_json::Value = serde_json::from_slice(&output.stdout).unwrap();
90-
assert_eq!(report["native"]["status"], "completed");
93+
assert_eq!(report["native"]["status"], "completed", "{report}");
9194
assert_eq!(report["syntax_precheck"], serde_json::Value::Null);
9295
assert_eq!(report["status"], "incomplete");
9396
assert_eq!(report["coverage_proven"], false);
@@ -106,7 +109,7 @@ fn changed_zig_executable_cannot_authorize_native_completion() {
106109
let tool = root.join("zig-tool");
107110
fs::write(
108111
&tool,
109-
"#!/bin/sh\nif [ \"$1\" = version ]; then printf '0.16.0\\n'; exit 0; fi\nif [ \"$1\" = ast-check ]; then printf '#changed\\n' >> \"$0\"; exit 0; fi\nexit 2\n",
112+
"#!/bin/sh\nif [ \"$1\" = version ]; then printf '0.16.0\\n'; exit 0; fi\nif [ \"$1\" = ast-check ]; then while IFS= read -r line; do :; done; printf '#changed\\n' >> \"$0\"; exit 0; fi\nexit 2\n",
110113
)
111114
.unwrap();
112115
fs::set_permissions(&tool, fs::Permissions::from_mode(0o700)).unwrap();

0 commit comments

Comments
 (0)