Skip to content

Commit

Permalink
Omit shebang lines on Windows (#1417)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Nov 19, 2022
1 parent 56feaee commit e27e12a
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/shebang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl<'line> Shebang<'line> {
}

pub(crate) fn include_shebang_line(&self) -> bool {
!matches!(self.interpreter_filename(), "cmd" | "cmd.exe")
!cfg!(windows) && !matches!(self.interpreter_filename(), "cmd" | "cmd.exe")
}
}

Expand Down Expand Up @@ -201,7 +201,14 @@ mod tests {
}

#[test]
fn include_shebang_line_other() {
#[cfg(not(windows))]
fn include_shebang_line_other_not_windows() {
assert!(Shebang::new("#!foo -c").unwrap().include_shebang_line());
}

#[test]
#[cfg(windows)]
fn include_shebang_line_other_windows() {
assert!(!Shebang::new("#!foo -c").unwrap().include_shebang_line());
}
}
31 changes: 31 additions & 0 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ test! {
stderr: "#!/bin/sh\necho hello\n",
}

#[cfg(not(windows))]
test! {
name: shebang_line_numbers,
justfile: r#"
Expand All @@ -1100,6 +1101,36 @@ test! {
#!/usr/bin/env cat
a
b
c
",
}

#[cfg(windows)]
test! {
name: shebang_line_numbers,
justfile: r#"
quiet:
#!/usr/bin/env cat
a
b
c
"#,
stdout: "
a
b
Expand Down
14 changes: 11 additions & 3 deletions tests/tempdir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,21 @@ fn test_tempdir_is_set() {
}
})
.current_dir("foo")
.stdout(
.stdout(if cfg!(windows) {
"
cat just*/foo
"
} else {
"
#!/usr/bin/env bash
cat just*/foo
",
)
"
})
.run();
}

0 comments on commit e27e12a

Please sign in to comment.