Skip to content

Commit

Permalink
test: close temp directories after usage
Browse files Browse the repository at this point in the history
  • Loading branch information
azzamsa committed Jun 18, 2024
1 parent ff0d459 commit 1a14652
Showing 1 changed file with 15 additions and 20 deletions.
35 changes: 15 additions & 20 deletions tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ fn help() -> Result<(), Box<dyn Error>> {
fn all() -> Result<(), Box<dyn Error>> {
let (temp_dir, config) = setup_config()?;
config.write_str(&config_base())?;
env::set_var(
"BILAL_CONFIG",
format!("{}/config.toml", temp_dir.path().display()),
);
env::set_var("BILAL_CONFIG", config.to_path_buf());

let mut cmd = Command::cargo_bin(crate_name!())?;
cmd.arg("all");
Expand All @@ -33,76 +30,74 @@ fn all() -> Result<(), Box<dyn Error>> {
cmd.assert()
.success()
.stdout(predicate::str::contains("AM").not());

temp_dir.close()?;
Ok(())
}

#[test]
fn current() -> Result<(), Box<dyn Error>> {
let (temp_dir, config) = setup_config()?;
config.write_str(&config_base())?;
env::set_var(
"BILAL_CONFIG",
format!("{}/config.toml", temp_dir.path().display()),
);
env::set_var("BILAL_CONFIG", config.to_path_buf());

let mut cmd = Command::cargo_bin(crate_name!())?;
cmd.arg("current").arg("--json");
// \u{23fa} : ⏺
cmd.assert()
.success()
.stdout(predicate::str::contains("\u{23fa}"));

temp_dir.close()?;
Ok(())
}

#[test]
fn next() -> Result<(), Box<dyn Error>> {
let (temp_dir, config) = setup_config()?;
config.write_str(&config_base())?;
env::set_var(
"BILAL_CONFIG",
format!("{}/config.toml", temp_dir.path().display()),
);
env::set_var("BILAL_CONFIG", config.to_path_buf());

let mut cmd = Command::cargo_bin(crate_name!())?;
cmd.arg("next").arg("--json");
// \u{25b6} : ▶
cmd.assert()
.success()
.stdout(predicate::str::contains("\u{25b6}"));

temp_dir.close()?;
Ok(())
}

#[test]
fn all_12h_format() -> Result<(), Box<dyn Error>> {
let (temp_dir, config) = setup_config()?;
config.write_str(&config_12h())?;
env::set_var(
"BILAL_CONFIG",
format!("{}/config.toml", temp_dir.path().display()),
);
env::set_var("BILAL_CONFIG", config.to_path_buf());

let mut cmd = Command::cargo_bin(crate_name!())?;
cmd.arg("all");
cmd.assert()
.success()
.stdout(predicate::str::contains("AM"));

temp_dir.close()?;
Ok(())
}

#[test]
fn next_12h_format() -> Result<(), Box<dyn Error>> {
let (temp_dir, config) = setup_config()?;
config.write_str(&config_12h())?;
env::set_var(
"BILAL_CONFIG",
format!("{}/config.toml", temp_dir.path().display()),
);
env::set_var("BILAL_CONFIG", config.to_path_buf());

let mut cmd = Command::cargo_bin(crate_name!())?;
cmd.arg("next");
cmd.assert()
.success()
.stdout(predicate::str::contains("AM").or(predicate::str::contains("PM")));

temp_dir.close()?;
Ok(())
}

Expand Down

0 comments on commit 1a14652

Please sign in to comment.