-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move test fixtures to new herostratus-tests crate
This enables sharing them between herostratus proper and the integration tests, while keeping them out of the public API of the herostratus library.
Showing
22 changed files
with
101 additions
and
174 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use std::path::{Path, PathBuf}; | ||
use std::process::Output; | ||
|
||
use assert_cmd::Command; | ||
use tempfile::{tempdir, TempDir}; | ||
|
||
lazy_static::lazy_static! { | ||
static ref HEROSTRATUS: PathBuf = assert_cmd::cargo::cargo_bin("herostratus"); | ||
} | ||
|
||
/// Get a [`Command`] for the herostratus binary and the [`TempDir`] data dir used in the test | ||
pub fn herostratus(data_dir: Option<&Path>) -> (Command, Option<TempDir>) { | ||
let (tempdir, path) = if let Some(data_dir) = data_dir { | ||
(None, data_dir.to_path_buf()) | ||
} else { | ||
let temp = tempdir().unwrap(); | ||
let data_dir = temp.path().to_path_buf(); | ||
(Some(temp), data_dir) | ||
}; | ||
|
||
let mut cmd = Command::new(&*HEROSTRATUS); | ||
cmd.arg("--log-level=DEBUG").arg("--data-dir").arg(path); | ||
|
||
(cmd, tempdir) | ||
} | ||
|
||
fn capture_output(output: &Output) { | ||
let stdout = String::from_utf8_lossy(&output.stdout); | ||
let stderr = String::from_utf8_lossy(&output.stderr); | ||
|
||
// Test output capture relies on magic in the print! and println! macros | ||
print!("{stdout}"); | ||
print!("{stderr}"); | ||
} | ||
|
||
pub trait CommandExt { | ||
/// Same as [Command::output], except with hooks to print stdout and stderr for failed tests | ||
fn captured_output(&mut self) -> std::io::Result<Output>; | ||
} | ||
|
||
impl CommandExt for Command { | ||
fn captured_output(&mut self) -> std::io::Result<Output> { | ||
let output = self.output()?; | ||
capture_output(&output); | ||
Ok(output) | ||
} | ||
} |
File renamed without changes.
1 change: 0 additions & 1 deletion
1
herostratus/src/test/fixtures/mod.rs → herostratus-tests/src/fixtures/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
pub mod config; | ||
pub mod repository; | ||
pub mod rule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod cmd; | ||
pub mod fixtures; | ||
|
||
use tracing::Level; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.