Omit shebang lines on Windows (#1417)

This commit is contained in:
Casey Rodarmor 2022-11-19 12:38:41 -08:00 committed by GitHub
parent 56feaeedc3
commit e27e12ab1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 5 deletions

View file

@ -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")
}
}
@ -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());
}
}

View file

@ -1081,6 +1081,7 @@ test! {
stderr: "#!/bin/sh\necho hello\n",
}
#[cfg(not(windows))]
test! {
name: shebang_line_numbers,
justfile: r#"
@ -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

View file

@ -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();
}