Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
replacing /Users/amitu/CLionProjects/fbt (temp dir) with <cwd> in std…
Browse files Browse the repository at this point in the history
…{out,err}
  • Loading branch information
amitu committed May 20, 2021
1 parent e00b7e9 commit 0c214f9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
14 changes: 7 additions & 7 deletions fbt_lib/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,35 +308,35 @@ 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",
});
}
}

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 });
}
Expand Down
19 changes: 19 additions & 0 deletions fbt_lib/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(), "<cwd>");
self.stderr = self.stderr.replace(private_v.as_str(), "<cwd>");
self.stdout = self.stdout.replace(v.as_str(), "<cwd>");
self.stderr = self.stderr.replace(v.as_str(), "<cwd>");

self
}
}

impl TryFrom<&std::process::Output> for Output {
type Error = &'static str;

Expand Down
13 changes: 13 additions & 0 deletions tests/09-output-containing-cwd/cmd.p1
Original file line number Diff line number Diff line change
@@ -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:

<cwd>


-- stderr:

<cwd>/foo
Empty file.
15 changes: 15 additions & 0 deletions tests/10-output-containing-cwd-without-input/cmd.p1
Original file line number Diff line number Diff line change
@@ -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:

<cwd>


-- stderr:

<cwd>/foo

0 comments on commit 0c214f9

Please sign in to comment.