Skip to content

Commit

Permalink
cli(test): merge stdout and stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
vrmiguel committed Nov 2, 2023
1 parent 315e5ae commit 4acfce4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
1 change: 1 addition & 0 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async-trait = "0.1.64"
bollard = "0.14.0"
clap = { version = "4.1.1", features = ["derive"] }
colorful = "0.2.2"
duct = "0.13.6"
elf = "0.7.2"
env_logger = "0.10.0"
flate2 = "1.0.25"
Expand Down
29 changes: 10 additions & 19 deletions cli/src/commands/test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use std::{
ffi::OsStr,
fs::File,
io::{BufWriter, Cursor, Read, Write},
os::unix::process::CommandExt,
path::{Path, PathBuf},
process::Command,
process::{Command, Stdio},
};

use anyhow::{bail, Context};
use clap::Args;
use duct::cmd;
use flate2::bufread::GzDecoder;
use serde::Deserialize;
use tar::{Entry, EntryType};
Expand Down Expand Up @@ -109,9 +108,7 @@ async fn extract_sql_and_expected_files(
let path = entry.path()?;

if check_parent("sql", &path) {
dbg!(&path);
let path_written = read_entry(tempdir, &mut entry)?;
dbg!(&path_written);
sql_files.push(path_written);
} else if check_parent("expected", &path) {
let path_written = read_entry(tempdir, &mut entry)?;
Expand Down Expand Up @@ -166,30 +163,24 @@ impl SubCommand for TestCommand {
bail!("Found no matching SQL file for {:?}", expected_file);
};

run_psql(&sql_path, &self.connstring)?;
break;
let obtained = run_psql(&sql_path, &self.connstring)?;
let expected = std::fs::read_to_string(expected_file)?;
}

// Run psql (see regress.py)

Ok(())
}
}

fn run_psql(script_path: &Path, connstring: &str) -> Result<String> {
let child = Command::new("psql")
.args(["--echo-errors", "--echo-all", "--quiet", "-f"])
.arg(script_path)
.arg(connstring)
.spawn()?;

let output = child.wait_with_output()?;
let _ = dbg!(String::from_utf8(output.stderr));
let output = cmd!("psql", "--echo-errors", "--echo-all", "--quiet", "-f", script_path, connstring)
.unchecked()
.stderr_to_stdout()
.read()?;

let mut file = File::create("/home/vrmiguel/trunk-test.out")?;
file.write_all(&output.stdout)?;
file.write_all(output.as_bytes())?;

String::from_utf8(output.stdout).map_err(Into::into)
Ok(output)
}

#[derive(Debug, PartialEq)]
Expand Down

0 comments on commit 4acfce4

Please sign in to comment.