Skip to content

Commit

Permalink
Remove libc dependency (#336)
Browse files Browse the repository at this point in the history
* remove libc dependency

* save snapshots from stdout
  • Loading branch information
ntBre authored Feb 14, 2025
1 parent bd55d59 commit d651277
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ edition = "2021"

[dependencies]
intder = { git = "https://github.com/ntBre/intder" }
libc = "0.2.169"
nalgebra = "0.33.2"
psqs = { git = "https://github.com/ntBre/psqs" }
rust-anpass = { git = "https://github.com/ntBre/rust-anpass" }
Expand Down
12 changes: 2 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::File, os::unix::prelude::AsRawFd, path::Path};
use std::path::Path;

use pbqff::{
cleanup,
Expand Down Expand Up @@ -75,15 +75,7 @@ fn main() -> Result<(), std::io::Error> {
if path.exists() && !args.overwrite {
die!("existing pbqff output. overwrite with -o/--overwrite");
}
let outfile = File::create(path).expect("failed to create outfile");
let logfile = File::create("pbqff.log").expect("failed to create log file");
let out_fd = outfile.as_raw_fd();
let log_fd = logfile.as_raw_fd();
// redirect stdout to outfile and stderr to logfile
unsafe {
libc::dup2(out_fd, 1);
libc::dup2(log_fd, 2);
}

let config = Config::load(&args.infile);
println!("PID: {}", std::process::id());
println!("version: {}", version());
Expand Down
10 changes: 5 additions & 5 deletions tests/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs::read_to_string, path::Path};
use std::path::Path;

use assert_cmd::Command;
use insta::{assert_snapshot, with_settings};
Expand All @@ -21,11 +21,11 @@ fn run(path: &str, other_files: &[&str]) -> std::io::Result<()> {
let assert = cmd.arg("pbqff.toml").current_dir(&dir).assert();
let output = assert.get_output();

let stderr = String::from_utf8_lossy(&output.stderr);
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"stderr: {}\nlog: {}",
String::from_utf8_lossy(&output.stderr),
read_to_string(dir.path().join("pbqff.log"))?,
"stderr: {stderr}\nstdout: {stdout}"
);

// filter out essentially all of the numerical results just to check that
Expand All @@ -49,7 +49,7 @@ fn run(path: &str, other_files: &[&str]) -> std::io::Result<()> {
snapshot_suffix => path

}, {
assert_snapshot!(read_to_string(dir.path().join("pbqff.out")).unwrap());
assert_snapshot!(stdout);
});

Ok(())
Expand Down

0 comments on commit d651277

Please sign in to comment.