Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions cli/tests/examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
4 changes: 2 additions & 2 deletions examples/test-usage-double-slash-old.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
4 changes: 2 additions & 2 deletions examples/test-usage-double-slash.js
Original file line number Diff line number Diff line change
@@ -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"
Expand Down