diff --git a/cli/tests/examples.rs b/cli/tests/examples.rs index 8ade9995..ffd3c5c8 100644 --- a/cli/tests/examples.rs +++ b/cli/tests/examples.rs @@ -107,6 +107,44 @@ fn test_new_usage_syntax_execution() { .stdout(contains("baz: myvalue")); } +/// Test that the new // [USAGE] syntax works correctly for non-shell script +#[test] +fn test_usage_double_slash_execution() { + let mut cmd = Command::new(cargo::cargo_bin!("usage")); + cmd.args([ + "exec", + "node", + "../examples/test-usage-double-slash.js", + "--debug", + "mycmd", + ]); + + cmd.assert() + .success() + .stdout(contains("debug: true")) + .stdout(contains("port: 3000")) + .stdout(contains("command: mycmd")); +} + +/// Test that the old //USAGE syntax (no space, no brackets) works correctly for non-shell script +#[test] +fn test_usage_double_slash_execution_old() { + let mut cmd = Command::new(cargo::cargo_bin!("usage")); + cmd.args([ + "exec", + "node", + "../examples/test-usage-double-slash-old.js", + "--debug", + "mycmd", + ]); + + cmd.assert() + .success() + .stdout(contains("debug: true")) + .stdout(contains("port: 3000")) + .stdout(contains("command: mycmd")); +} + /// Test that blank comment lines in USAGE blocks don't stop parsing #[test] fn test_blank_comment_lines_in_usage() { diff --git a/examples/test-usage-double-slash-old.js b/examples/test-usage-double-slash-old.js index e23637dc..ad353e1e 100755 --- a/examples/test-usage-double-slash-old.js +++ b/examples/test-usage-double-slash-old.js @@ -1,6 +1,6 @@ -#!/usr/bin/env -S usage node +#!/usr/bin/env -S usage exec node // -// Test script for old USAGE syntax with // comments +// Test non-shell script for old USAGE syntax with // comments // //USAGE bin "test-double-slash-old" //USAGE flag "--debug" help="Debug mode" diff --git a/examples/test-usage-double-slash.js b/examples/test-usage-double-slash.js index 41a4b011..f69c6b94 100755 --- a/examples/test-usage-double-slash.js +++ b/examples/test-usage-double-slash.js @@ -1,6 +1,6 @@ -#!/usr/bin/env -S usage node +#!/usr/bin/env -S usage exec node // -// Test script for new USAGE syntax with // comments +// Test non-shell script for new USAGE syntax with // comments // // [USAGE] bin "test-double-slash" // [USAGE] flag "--debug" help="Debug mode"