Skip to content

Commit 5ddd61d

Browse files
committed
show-env: Add --csh
1 parent 4ddedae commit 5ddd61d

File tree

7 files changed

+89
-11
lines changed

7 files changed

+89
-11
lines changed

.github/.cspell/project-dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ profraw
2222
rmeta
2323
rustfilt
2424
rustix
25+
tcsh
2526
TESTNAME
2627
winapi
2728
xargo

.github/workflows/ci.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,26 @@ jobs:
272272
if: startsWith(matrix.os, 'windows')
273273
- name: Install other shells (Ubuntu)
274274
run: |
275-
sudo apt-get -o Acquire::Retries=10 -qq update
276-
sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends fish zsh
275+
retry() {
276+
for i in {1..10}; do
277+
if "$@"; then
278+
return 0
279+
else
280+
sleep "${i}"
281+
fi
282+
done
283+
"$@"
284+
}
285+
retry sudo apt-get -o Acquire::Retries=10 -qq update
286+
retry sudo apt-get -o Acquire::Retries=10 -o Dpkg::Use-Pty=0 install -y --no-install-recommends csh fish tcsh zsh
277287
if: startsWith(matrix.os, 'ubuntu') || matrix.os == ''
278288
- name: Install other shells (macOS)
279289
run: |
280-
brew install fish
290+
brew install fish tcsh
281291
if: startsWith(matrix.os, 'macos')
282292
- name: Install other shells (Windows)
283293
run: |
284-
C:/msys64/usr/bin/pacman -S --noconfirm fish zsh
294+
C:/msys64/usr/bin/pacman -S --noconfirm fish tcsh zsh
285295
printf '%s\n' 'C:\msys64\usr\bin' >>"${GITHUB_PATH}"
286296
# TODO: C:/msys64/usr/bin/pacman: No such file or directory
287297
if: startsWith(matrix.os, 'windows') && matrix.os != 'windows-11-arm'
@@ -301,6 +311,37 @@ jobs:
301311
shell: zsh {0}
302312
working-directory: tests/fixtures/crates/bin_crate
303313
if: matrix.os != 'windows-11-arm'
314+
- name: Test show-env --csh on csh
315+
run: |
316+
cargo llvm-cov show-env --csh > env.csh
317+
source ./env.csh
318+
cargo llvm-cov clean --workspace
319+
cargo build
320+
cargo run -- 1
321+
cargo llvm-cov report --fail-under-lines 50
322+
cargo llvm-cov clean --workspace
323+
cargo build
324+
cargo run -- 2
325+
cargo llvm-cov report --fail-under-lines 50
326+
shell: bsd-csh {0}
327+
working-directory: tests/fixtures/crates/bin_crate
328+
if: startsWith(matrix.os, 'ubuntu') || matrix.os == ''
329+
- name: Test show-env --csh on tcsh
330+
run: |
331+
tcsh --version
332+
cargo llvm-cov show-env --csh > env.csh
333+
source ./env.csh
334+
cargo llvm-cov clean --workspace
335+
cargo build
336+
cargo run -- 1
337+
cargo llvm-cov report --fail-under-lines 50
338+
cargo llvm-cov clean --workspace
339+
cargo build
340+
cargo run -- 2
341+
cargo llvm-cov report --fail-under-lines 50
342+
shell: tcsh {0}
343+
working-directory: tests/fixtures/crates/bin_crate
344+
if: matrix.os != 'windows-11-arm'
304345
- name: Test show-env --fish
305346
run: |
306347
cargo llvm-cov show-env --sh > env.fish

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com
1212

1313
## [Unreleased]
1414

15+
- Add `--csh` to `cargo llvm-cov show-env` for csh and tcsh.
16+
1517
- Diagnostics improvements.
1618

1719
## [0.8.2] - 2026-01-27

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ cargo llvm-cov report --lcov # Generate report without tests.
506506
> ```
507507
>
508508
> See "Test show-env ... on ..." in [our CI config](https://github.com/taiki-e/cargo-llvm-cov/blob/HEAD/.github/workflows/ci.yml)
509-
> for usage with other shells.
509+
> for usage with other shells (cmd.exe, csh, tcsh, fish).
510510
511511
### Get coverage of AFL fuzzers
512512

docs/cargo-llvm-cov-show-env.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ OPTIONS:
1414
--cmd
1515
Make output suitable to be called by cmd.exe
1616

17+
--csh
18+
Make output suitable to be sourced by csh and tcsh
19+
1720
--fish
1821
Make output suitable to be sourced by fish
1922

src/cli.rs

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -576,20 +576,25 @@ pub(crate) enum ShowEnvFormat {
576576
Pwsh,
577577
/// Each key-value: `set {key}={value}`, where `{value}` is escaped using [`shell_escape::windows::escape`].
578578
Cmd,
579+
/// Each key-value: `setenv {key} '{value}'`, where `{value}` is escaped using [`shell_escape::unix::escape`].
580+
Csh,
579581
/// Each key-value: `set -gx {key}={value}`, where `{value}` is escaped using [`shell_escape::unix::escape`].
580582
Fish,
581583
}
582584

583585
impl ShowEnvFormat {
584586
#[allow(clippy::fn_params_excessive_bools)]
585-
pub(crate) fn new(sh: bool, pwsh: bool, cmd: bool, fish: bool) -> Result<Self> {
587+
pub(crate) fn new(sh: bool, pwsh: bool, cmd: bool, csh: bool, fish: bool) -> Result<Self> {
586588
Ok(if sh {
587589
if pwsh {
588590
conflicts("--sh", "--pwsh")?;
589591
}
590592
if cmd {
591593
conflicts("--sh", "--cmd")?;
592594
}
595+
if csh {
596+
conflicts("--sh", "--csh")?;
597+
}
593598
if fish {
594599
conflicts("--sh", "--fish")?;
595600
}
@@ -598,15 +603,26 @@ impl ShowEnvFormat {
598603
if cmd {
599604
conflicts("--pwsh", "--cmd")?;
600605
}
606+
if csh {
607+
conflicts("--pwsh", "--csh")?;
608+
}
601609
if fish {
602610
conflicts("--pwsh", "--fish")?;
603611
}
604612
ShowEnvFormat::Pwsh
605613
} else if cmd {
614+
if csh {
615+
conflicts("--cmd", "--csh")?;
616+
}
606617
if fish {
607618
conflicts("--cmd", "--fish")?;
608619
}
609620
ShowEnvFormat::Cmd
621+
} else if csh {
622+
if fish {
623+
conflicts("--csh", "--fish")?;
624+
}
625+
ShowEnvFormat::Csh
610626
} else if fish {
611627
ShowEnvFormat::Fish
612628
} else {
@@ -634,6 +650,15 @@ impl ShowEnvFormat {
634650
ShowEnvFormat::Cmd => {
635651
writeln!(writer, "set {key}={}", escape::cmd(value.into()))
636652
}
653+
ShowEnvFormat::Csh => {
654+
// TODO: https://en.wikipedia.org/wiki/C_shell#Quoting_and_escaping
655+
let value = escape::sh(value.into());
656+
if value.starts_with('"') || value.starts_with('\'') {
657+
writeln!(writer, "setenv {key} {value}")
658+
} else {
659+
writeln!(writer, "setenv {key} '{value}'")
660+
}
661+
}
637662
ShowEnvFormat::Fish => {
638663
// TODO: https://fishshell.com/docs/current/language.html#quotes
639664
writeln!(writer, "set -gx {key}={}", escape::sh(value.into()))
@@ -781,6 +806,7 @@ impl Args {
781806
let mut sh = false;
782807
let mut pwsh = false;
783808
let mut cmd = false;
809+
let mut csh = false;
784810
let mut fish = false;
785811

786812
// options ambiguous between nextest-related and others
@@ -994,6 +1020,7 @@ impl Args {
9941020
parse_flag!(pwsh);
9951021
}
9961022
Long("cmd") => parse_flag!(cmd),
1023+
Long("csh") => parse_flag!(csh),
9971024
Long("fish") => parse_flag!(fish),
9981025

9991026
// ambiguous between nextest-related and others will be handled later
@@ -1099,11 +1126,15 @@ impl Args {
10991126
// Handle options specific to certain subcommands.
11001127
// show-env specific
11011128
let show_env_format = match subcommand {
1102-
Subcommand::ShowEnv => ShowEnvFormat::new(sh, pwsh, cmd, fish)?,
1129+
Subcommand::ShowEnv => ShowEnvFormat::new(sh, pwsh, cmd, csh, fish)?,
11031130
_ => {
1104-
for (passed, flag) in
1105-
[(sh, "--sh"), (pwsh, "--pwsh"), (cmd, "--cmd"), (fish, "--fish")]
1106-
{
1131+
for (passed, flag) in [
1132+
(sh, "--sh"),
1133+
(pwsh, "--pwsh"),
1134+
(cmd, "--cmd"),
1135+
(csh, "--csh"),
1136+
(fish, "--fish"),
1137+
] {
11071138
if passed {
11081139
specific_flag(flag, subcommand, &["show-env"])?;
11091140
}

tests/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ fn invalid_arg() {
416416
["", "test", "run", "report", "clean", "show-env", "nextest", "nextest-archive"]
417417
{
418418
if subcommand != "show-env" {
419-
for flag in ["--sh", "--pwsh", "--cmd", "--fish"] {
419+
for flag in ["--sh", "--pwsh", "--cmd", "--csh", "--fish"] {
420420
cargo_llvm_cov(subcommand)
421421
.arg(flag)
422422
.assert_failure()

0 commit comments

Comments
 (0)