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
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bzip2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,12 +1513,13 @@ unsafe fn uncompress(name: Option<String>) {
outStr = stdout;
if inStr.is_null() {
eprintln!(
"{}: Can't open input file {}:{}.",
"{}: Can't open input file {}: {}.",
get_program_name().display(),
in_name.display(),
display_last_os_error(),
);
if !inStr.is_null() {
// this is unreachable, but in the original C source code
folkertdev marked this conversation as resolved.
Show resolved Hide resolved
fclose(inStr);
}
setExit(1);
Expand Down
26 changes: 25 additions & 1 deletion tests/quick.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ mod decompress_command {

#[cfg(unix)]
#[test]
fn decompress_input_file_cannot_be_read() {
fn input_file_cannot_be_read_f2f() {
use std::os::unix::fs::PermissionsExt;

let tmpdir = tempfile::tempdir().unwrap();
Expand Down Expand Up @@ -761,6 +761,30 @@ mod decompress_command {
),
);
}

#[test]
fn input_file_cannot_be_read_f2o() {
use std::os::unix::fs::PermissionsExt;

let tmpdir = tempfile::tempdir().unwrap();
let sample1 = tmpdir.path().join("sample1.bz2");

std::fs::copy("tests/input/quick/sample1.bz2", &sample1).unwrap();

let mut permissions = std::fs::metadata(&sample1).unwrap().permissions();
permissions.set_mode(0o000); // no permissions for you
std::fs::set_permissions(&sample1, permissions).unwrap();

let mut cmd = command();

expect_failure!(
cmd.arg("-d").arg(&sample1).arg("-c").stdout(Stdio::piped()),
format!(
"bzip2: Can't open input file {in_file}: Permission denied.\n",
in_file = sample1.display()
)
);
}
}

mod test_command {
Expand Down