Skip to content

Commit 2760fe1

Browse files
committed
test: add non-shell script tests
1 parent 6fd62b4 commit 2760fe1

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

cli/tests/examples.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,44 @@ fn test_new_usage_syntax_execution() {
107107
.stdout(contains("baz: myvalue"));
108108
}
109109

110+
/// Test that the new // [USAGE] syntax works correctly for non-shell script
111+
#[test]
112+
fn test_usage_double_slash_execution() {
113+
let mut cmd = Command::new(cargo::cargo_bin!("usage"));
114+
cmd.args([
115+
"exec",
116+
"node",
117+
"../examples/test-usage-double-slash.js",
118+
"--debug",
119+
"mycmd",
120+
]);
121+
122+
cmd.assert()
123+
.success()
124+
.stdout(contains("debug: true"))
125+
.stdout(contains("port: 3000"))
126+
.stdout(contains("command: mycmd"));
127+
}
128+
129+
/// Test that the //Usage syntax (no space) works correctly for non-shell script
130+
#[test]
131+
fn test_usage_double_slash_execution_old() {
132+
let mut cmd = Command::new(cargo::cargo_bin!("usage"));
133+
cmd.args([
134+
"exec",
135+
"node",
136+
"../examples/test-usage-double-slash-old.js",
137+
"--debug",
138+
"mycmd",
139+
]);
140+
141+
cmd.assert()
142+
.success()
143+
.stdout(contains("debug: true"))
144+
.stdout(contains("port: 3000"))
145+
.stdout(contains("command: mycmd"));
146+
}
147+
110148
/// Test that blank comment lines in USAGE blocks don't stop parsing
111149
#[test]
112150
fn test_blank_comment_lines_in_usage() {

examples/test-usage-double-slash-old.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/env -S usage node
1+
#!/usr/bin/env -S usage exec node
22
//
3-
// Test script for old USAGE syntax with // comments
3+
// Test non-shell script for old USAGE syntax with // comments
44
//
55
//USAGE bin "test-double-slash-old"
66
//USAGE flag "--debug" help="Debug mode"

examples/test-usage-double-slash.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/env -S usage node
1+
#!/usr/bin/env -S usage exec node
22
//
3-
// Test script for new USAGE syntax with // comments
3+
// Test non-shell script for new USAGE syntax with // comments
44
//
55
// [USAGE] bin "test-double-slash"
66
// [USAGE] flag "--debug" help="Debug mode"

0 commit comments

Comments
 (0)