Skip to content

Commit cd288fc

Browse files
authored
ci: ensure test failures are caught in coverage script and fix them (#10286)
1 parent 48a0db8 commit cd288fc

File tree

4 files changed

+27
-13
lines changed

4 files changed

+27
-13
lines changed

src/uucore/src/lib/features/proc_info.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,11 +465,16 @@ mod tests {
465465
.flat_map(Teletype::try_from)
466466
.collect::<HashSet<_>>();
467467

468-
assert_eq!(result.len(), 1);
469-
assert_eq!(
470-
pid_entry.tty(),
471-
Vec::from_iter(result.into_iter()).first().unwrap().clone()
472-
);
468+
// In CI environments or when running without a terminal, there may be no TTY
469+
if result.is_empty() {
470+
assert_eq!(pid_entry.tty(), Teletype::Unknown);
471+
} else {
472+
assert_eq!(result.len(), 1);
473+
assert_eq!(
474+
pid_entry.tty(),
475+
Vec::from_iter(result.into_iter()).first().unwrap().clone()
476+
);
477+
}
473478
}
474479

475480
#[test]

src/uucore/src/lib/features/process.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,11 @@ pub fn getpid() -> pid_t {
6767
/// so some system such as redox doesn't supported.
6868
#[cfg(not(target_os = "redox"))]
6969
pub fn getsid(pid: i32) -> Result<pid_t, Errno> {
70-
unsafe {
71-
let result = libc::getsid(pid);
72-
if Errno::last() == Errno::UnknownErrno {
73-
Ok(result)
74-
} else {
75-
Err(Errno::last())
76-
}
70+
let result = unsafe { libc::getsid(pid) };
71+
if result == -1 {
72+
Err(Errno::last())
73+
} else {
74+
Ok(result)
7775
}
7876
}
7977

tests/by-util/test_dd.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,8 @@ fn test_reading_partial_blocks_from_fifo() {
16551655
.stdout(Stdio::piped())
16561656
.stderr(Stdio::piped())
16571657
.env("LC_ALL", "C")
1658+
.env("LANG", "C")
1659+
.env("LANGUAGE", "C")
16581660
.spawn()
16591661
.unwrap();
16601662

@@ -1700,6 +1702,8 @@ fn test_reading_partial_blocks_from_fifo_unbuffered() {
17001702
.stdout(Stdio::piped())
17011703
.stderr(Stdio::piped())
17021704
.env("LC_ALL", "C")
1705+
.env("LANG", "C")
1706+
.env("LANGUAGE", "C")
17031707
.spawn()
17041708
.unwrap();
17051709

util/build-run-test-coverage-linux.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
set -e
2929
# Treat unset variables as errors
3030
set -u
31+
# Ensure pipeline failures are caught (not just the last command's exit code)
32+
set -o pipefail
3133
# Print expanded commands to stdout before running them
3234
set -x
3335

@@ -39,7 +41,12 @@ REPO_main_dir="$(dirname -- "${ME_dir}")"
3941
FEATURES_OPTION=${FEATURES_OPTION:-"--features=feat_os_unix"}
4042
COVERAGE_DIR=${COVERAGE_DIR:-"${REPO_main_dir}/coverage"}
4143

42-
LLVM_PROFDATA="$(find "$(rustc --print sysroot)" -name llvm-profdata)"
44+
# Find llvm-profdata in the nightly toolchain (which is used for coverage builds)
45+
LLVM_PROFDATA="$(find "$(RUSTUP_TOOLCHAIN=nightly-gnu rustc --print sysroot)" -name llvm-profdata)"
46+
if [ -z "${LLVM_PROFDATA}" ]; then
47+
echo "Error: llvm-profdata not found. Install it with: rustup +nightly-gnu component add llvm-tools"
48+
exit 1
49+
fi
4350

4451
PROFRAW_DIR="${COVERAGE_DIR}/traces"
4552
PROFDATA_DIR="${COVERAGE_DIR}/data"

0 commit comments

Comments
 (0)