Skip to content

Commit

Permalink
add test to compare new default output
Browse files Browse the repository at this point in the history
  • Loading branch information
marcospb19 committed Dec 26, 2022
1 parent f25ec8b commit d78a8eb
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ predicates = "2.1.1"
tempfile = "3.3.0"
which = { version = "4.3.0", default-features = false }
pretty_assertions = "1.3"
regex = "1.7.0"
unindent = "0.1.11"
46 changes: 46 additions & 0 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use predicates::{
};
#[allow(unused_imports)]
use pretty_assertions::{assert_eq, assert_ne};
use regex::Regex;
use tempfile::{tempdir, TempDir};
use unindent::unindent;

struct AnyhowWithContext(anyhow::Error);
impl Debug for AnyhowWithContext {
Expand Down Expand Up @@ -142,6 +144,11 @@ fn count_cleaned_dry_run(target: &TempDir, args: &[&str], old_size: u64) -> Resu
Ok(cleaned)
}

fn regex_matches(pattern: &str, text: &str) -> bool {
let pattern = Regex::new(pattern).expect("Failed to compile regex pattern");
pattern.is_match(text)
}

#[test]
fn all_flags() -> TestResult {
let all_combos = [
Expand Down Expand Up @@ -192,6 +199,45 @@ fn stamp_file() -> TestResult {
Ok(())
}

#[test]
fn empty_project_output() -> TestResult {
let (_size, target) = build("sample-project")?;

let assert = run(
sweep(&["--maxsize", "0"]).current_dir(test_dir().join("sample-project")),
target.path(),
);

let output = std::str::from_utf8(&assert.get_output().stdout).unwrap();

let regex_skip = r#".+?"#;

let pattern = unindent(&format!(
r#"\[DEBUG\] cleaning: "/tmp/{regex_skip}" with remove_older_until_fits
\[DEBUG\] size_to_remove: {regex_skip}
\[DEBUG\] Sizing: "/tmp/{regex_skip}/debug" with total_disk_space_in_a_profile
\[DEBUG\] Hashs by time: \[
\(
{regex_skip},
"{regex_skip}",
\),
\]
\[DEBUG\] cleaning: "/tmp/{regex_skip}/debug" with remove_not_built_with_in_a_profile
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/deps/libsample_project-{regex_skip}.rlib"
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/deps/libsample_project-{regex_skip}.rmeta"
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/deps/sample_project-{regex_skip}.d"
\[DEBUG\] Successfully removed: "/tmp/{regex_skip}/debug/.fingerprint/sample-project-{regex_skip}"
\[INFO\] Cleaned {regex_skip} from "/tmp/{regex_skip}""#,
));

assert!(
regex_matches(&pattern, output),
"failed to match pattern with output"
);

Ok(())
}

#[test]
fn hidden() -> TestResult {
// This path is so strange because we use CARGO_TARGET_DIR to set the target to a temporary directory.
Expand Down

0 comments on commit d78a8eb

Please sign in to comment.