mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix: Deno.noColor should not be true when NO_COLOR is empty string (#21275)
Closes https://github.com/denoland/deno/issues/21274
This commit is contained in:
parent
c97a97240b
commit
1eefe3e42b
2 changed files with 34 additions and 2 deletions
|
@ -24,3 +24,32 @@ Deno.test(
|
|||
assertEquals(output, "false\n");
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { run: true, read: true } },
|
||||
async function denoNoColorTrueEmptyVar() {
|
||||
const { stdout } = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "console.log(Deno.noColor)"],
|
||||
env: {
|
||||
// https://no-color.org/ -- should not be true when empty
|
||||
NO_COLOR: "",
|
||||
},
|
||||
}).output();
|
||||
const output = new TextDecoder().decode(stdout);
|
||||
assertEquals(output, "false\n");
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{ permissions: { run: true, read: true } },
|
||||
async function denoNoColorTrueEmptyVar() {
|
||||
const { stdout } = await new Deno.Command(Deno.execPath(), {
|
||||
args: ["eval", "console.log(Deno.noColor)"],
|
||||
env: {
|
||||
NO_COLOR: "1",
|
||||
},
|
||||
}).output();
|
||||
const output = new TextDecoder().decode(stdout);
|
||||
assertEquals(output, "true\n");
|
||||
},
|
||||
);
|
||||
|
|
|
@ -22,8 +22,11 @@ use termcolor::BufferWriter;
|
|||
#[cfg(windows)]
|
||||
use termcolor::ColorChoice;
|
||||
|
||||
static NO_COLOR: Lazy<bool> =
|
||||
Lazy::new(|| std::env::var_os("NO_COLOR").is_some());
|
||||
static NO_COLOR: Lazy<bool> = Lazy::new(|| {
|
||||
std::env::var_os("NO_COLOR")
|
||||
.map(|v| !v.is_empty())
|
||||
.unwrap_or(false)
|
||||
});
|
||||
|
||||
static IS_TTY: Lazy<bool> = Lazy::new(|| std::io::stdout().is_terminal());
|
||||
|
||||
|
|
Loading…
Reference in a new issue