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
6 changes: 6 additions & 0 deletions src/shell/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ pub fn builtin_commands() -> HashMap<String, Rc<dyn ShellCommand>> {
"false".to_string(),
Rc::new(ExitCodeCommand(1)) as Rc<dyn ShellCommand>,
),
// POSIX null command: discards its arguments and always exits 0.
// Commonly seen as `"test": ":"` in package.json no-op scripts.
(
":".to_string(),
Rc::new(ExitCodeCommand(0)) as Rc<dyn ShellCommand>,
),
(
"unset".to_string(),
Rc::new(unset::UnsetCommand) as Rc<dyn ShellCommand>,
Expand Down
18 changes: 18 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ async fn boolean_logic() {
.await;
}

#[tokio::test]
async fn null_command() {
// POSIX `:` is the null command — always succeeds, discards args.
TestBuilder::new().command(":").run().await;

TestBuilder::new()
.command(": ignored args && echo ok")
.assert_stdout("ok\n")
.run()
.await;

TestBuilder::new()
.command(": && echo yes || echo no")
.assert_stdout("yes\n")
.run()
.await;
}

#[tokio::test]
async fn exit() {
TestBuilder::new()
Expand Down
Loading