Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bzip2.rs: improve test coverage #31

Merged
merged 15 commits into from
Nov 12, 2024
Merged

bzip2.rs: improve test coverage #31

merged 15 commits into from
Nov 12, 2024

Conversation

folkertdev
Copy link
Collaborator

@folkertdev folkertdev commented Nov 11, 2024

moves the tests around, and adds some additional coverage.

Codecov is not happy, but actuall if you look at it it's fine (the "uncovered lines" are comments...)

@folkertdev folkertdev force-pushed the bzip2-test-coverage branch 7 times, most recently from 8ad5cc5 to 77f0f9c Compare November 11, 2024 20:16
Copy link

codecov bot commented Nov 11, 2024

Codecov Report

Attention: Patch coverage is 50.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
bzip2.rs 50.00% 2 Missing ⚠️
Files with missing lines Coverage Δ
bzip2.rs 78.96% <50.00%> (ø)

... and 1 file with indirect coverage changes

tests/quick.rs Outdated
Comment on lines 76 to 125
#[cfg(unix)]
unsafe fn custom_tty() -> (
std::sync::MutexGuard<'static, ()>,
std::process::Stdio,
std::process::Stdio,
) {
use std::{os::fd::FromRawFd, sync::Mutex};

// only one thread should be doing this at a time
static X: Mutex<()> = Mutex::new(());

let guard = X.lock().unwrap();

// Open the master PTY using libc
let cstring = std::ffi::CString::new("/dev/ptmx").unwrap();
let master_fd = unsafe { libc::open(cstring.as_ptr(), libc::O_RDWR) };
if master_fd < 0 {
panic!("{}", std::io::Error::last_os_error());
}

// Grant access to the slave PTY
if unsafe { libc::grantpt(master_fd) } < 0 {
panic!("{}", std::io::Error::last_os_error());
}

// Unlock the slave PTY
if unsafe { libc::unlockpt(master_fd) } < 0 {
panic!("{}", std::io::Error::last_os_error());
}

// Get the path to the slave PTY
let slave_path_ptr = unsafe { libc::ptsname(master_fd) };
if slave_path_ptr.is_null() {
panic!("{}", std::io::Error::last_os_error());
}

// Open the slave PTY
let slave_fd = unsafe { libc::open(slave_path_ptr, libc::O_RDWR) };
if slave_fd < 0 {
panic!("{}", std::io::Error::last_os_error());
}

unsafe {
(
guard,
Stdio::from_raw_fd(master_fd),
Stdio::from_raw_fd(slave_fd),
)
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the internet told me this is how to set up a TTY. it appears to work well as a stdout device, but not for stdin. It does work locally but that might be because of my shell? anyway on CI it does not work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the TTY stuff for now, the other changes are more important

Base automatically changed from cleanup-test to main November 12, 2024 09:07
bzip2.rs Outdated Show resolved Hide resolved
Co-authored-by: bjorn3 <[email protected]>
@folkertdev folkertdev merged commit a192378 into main Nov 12, 2024
10 of 11 checks passed
@folkertdev folkertdev deleted the bzip2-test-coverage branch November 12, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants