From 2760fe1fbcf1e1523c3c7e65679f89f8487c861c Mon Sep 17 00:00:00 2001 From: Yukai Chou Date: Sat, 20 Dec 2025 01:40:20 +0800 Subject: [PATCH 1/2] test: add non-shell script tests --- cli/tests/examples.rs | 38 +++++++++++++++++++++++++ examples/test-usage-double-slash-old.js | 4 +-- examples/test-usage-double-slash.js | 4 +-- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cli/tests/examples.rs b/cli/tests/examples.rs index 8ade9995..0c7932a4 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 //Usage syntax (no space) 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" From 967b94ecf18eeee6f46aa9e626324484817d1a30 Mon Sep 17 00:00:00 2001 From: Yukai Chou Date: Wed, 24 Dec 2025 03:49:45 +0800 Subject: [PATCH 2/2] Update cli/tests/examples.rs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- cli/tests/examples.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/tests/examples.rs b/cli/tests/examples.rs index 0c7932a4..ffd3c5c8 100644 --- a/cli/tests/examples.rs +++ b/cli/tests/examples.rs @@ -126,7 +126,7 @@ fn test_usage_double_slash_execution() { .stdout(contains("command: mycmd")); } -/// Test that the //Usage syntax (no space) works correctly for non-shell script +/// 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"));