From 0c214f9cb33f99d01c689fac73ed36cbd4cf2bfb Mon Sep 17 00:00:00 2001 From: Amit Upadhyay Date: Thu, 20 May 2021 10:34:55 +0530 Subject: [PATCH] replacing /Users/amitu/CLionProjects/fbt (temp dir) with in std{out,err} --- fbt_lib/src/run.rs | 14 +++++++------- fbt_lib/src/types.rs | 19 +++++++++++++++++++ tests/09-output-containing-cwd/cmd.p1 | 13 +++++++++++++ tests/09-output-containing-cwd/input/.keep | 0 .../cmd.p1 | 15 +++++++++++++++ 5 files changed, 54 insertions(+), 7 deletions(-) create mode 100644 tests/09-output-containing-cwd/cmd.p1 create mode 100644 tests/09-output-containing-cwd/input/.keep create mode 100644 tests/10-output-containing-cwd-without-input/cmd.p1 diff --git a/fbt_lib/src/run.rs b/fbt_lib/src/run.rs index 5f564b7..99c21b7 100644 --- a/fbt_lib/src/run.rs +++ b/fbt_lib/src/run.rs @@ -308,18 +308,18 @@ fn test_one(global: &crate::Config, entry: std::path::PathBuf) -> crate::Case { // eprintln!("executing '{}' in {:?}", &config.cmd, &dir); let mut child = match config.cmd().current_dir(&dir).spawn() { Ok(c) => c, - Err(e) => { + Err(io) => { return err(crate::Failure::CommandFailed { - io: e, + io, reason: "cant fork process", }); } }; if let (Some(ref stdin), Some(cstdin)) = (config.stdin, &mut child.stdin) { - if let Err(e) = cstdin.borrow_mut().write_all(stdin.as_bytes()) { + if let Err(io) = cstdin.borrow_mut().write_all(stdin.as_bytes()) { return err(crate::Failure::CommandFailed { - io: e, + io, reason: "cant write to stdin", }); } @@ -327,16 +327,16 @@ fn test_one(global: &crate::Config, entry: std::path::PathBuf) -> crate::Case { let output = match child.wait_with_output() { Ok(o) => o, - Err(e) => { + Err(io) => { return err(crate::Failure::CommandFailed { - io: e, + io, reason: "cant wait", }) } }; let output = match crate::Output::try_from(&output) { - Ok(o) => o, + Ok(o) => o.replace(dir.to_string_lossy().to_string()), Err(reason) => { return err(crate::Failure::CantReadOutput { reason, output }); } diff --git a/fbt_lib/src/types.rs b/fbt_lib/src/types.rs index ba307f0..6c5c59b 100644 --- a/fbt_lib/src/types.rs +++ b/fbt_lib/src/types.rs @@ -270,6 +270,25 @@ pub struct Output { pub stderr: String, } +impl Output { + pub fn replace(mut self, v: String) -> Self { + // on mac /private is added to temp folders + // amitu@MacBook-Pro fbt % ls /var/folders/kf/jfmbkscj7757mmr29mn3rksm0000gn/T/fbt/874862845293569866/input + // one + // amitu@MacBook-Pro fbt % ls /private/var/folders/kf/jfmbkscj7757mmr29mn3rksm0000gn/T/fbt/874862845293569866/input + // one + // both of them are the same folder, and we see the former path, but the lauched processes see the later + + let private_v = format!("/private{}", v.as_str()); + self.stdout = self.stdout.replace(private_v.as_str(), ""); + self.stderr = self.stderr.replace(private_v.as_str(), ""); + self.stdout = self.stdout.replace(v.as_str(), ""); + self.stderr = self.stderr.replace(v.as_str(), ""); + + self + } +} + impl TryFrom<&std::process::Output> for Output { type Error = &'static str; diff --git a/tests/09-output-containing-cwd/cmd.p1 b/tests/09-output-containing-cwd/cmd.p1 new file mode 100644 index 0000000..905b66c --- /dev/null +++ b/tests/09-output-containing-cwd/cmd.p1 @@ -0,0 +1,13 @@ +-- fbt: +cmd: echo $PWD && echo $PWD/foo 1>&2 + +In this test we ensure that we strip out temp dir from stdout and stderr. + +-- stdout: + + + + +-- stderr: + +/foo \ No newline at end of file diff --git a/tests/09-output-containing-cwd/input/.keep b/tests/09-output-containing-cwd/input/.keep new file mode 100644 index 0000000..e69de29 diff --git a/tests/10-output-containing-cwd-without-input/cmd.p1 b/tests/10-output-containing-cwd-without-input/cmd.p1 new file mode 100644 index 0000000..79ca2a8 --- /dev/null +++ b/tests/10-output-containing-cwd-without-input/cmd.p1 @@ -0,0 +1,15 @@ +-- fbt: +cmd: echo $PWD && echo $PWD/foo 1>&2 + +In this test we ensure that we strip out temp dir from stdout and stderr. + +This one is without input folder present in test case. + +-- stdout: + + + + +-- stderr: + +/foo \ No newline at end of file