Repository: sharkdp/bat
File: tests/integration_tests.rs (Rust)

Code before:

    // Now we expect the file to exist. If it exists, we assume contents are correct
    assert!(tmp_config_path.exists());
}

#[test]
fn config_location_from_bat_config_dir_variable() {
    bat_with_config()
        .env("BAT_CONFIG_DIR", "conf/")
        .arg("--config-file")
        .assert()
        .success()
        .stdout(predicate::str::is_match("conf/config\n").unwrap());
}

#[test]
fn config_read_arguments_from_file() {
    bat_with_config()
        .env("BAT_CONFIG_PATH", "bat.conf")
        .arg("test.txt")
        .assert()
        .success()
        .stdout(predicate::eq("dummy-pager-from-config\n").normalize());
}

// ignore this test for now as cargo cache --clear only targets the default projects dir
#[cfg(unix)]
#[test]
#[ignore]
fn cache_clear() {
    let src_dir = "cache_source";
    let tmp_dir = tempdir().expect("can create temporary directory");
    let themes_filename = "themes.bin";
    let syntaxes_filename = "syntaxes.bin";
    let metadata_filename = "metadata.yaml";
    [themes_filename, syntaxes_filename, metadata_filename]
        .iter()
        .map(|filename| {
            let fp = tmp_dir.path().join(filename);
            let mut file = File::create(fp).expect("can create temporary file");
            writeln!(file, "dummy content").expect("can write to file");
        })
        .count();

    // Clear the targeted cache
    bat_with_config()
        .current_dir(Path::new(EXAMPLES_DIR).join(src_dir))
        .env("BAT_CONFIG_PATH", "bat.conf")
        .env("BAT_THEME", "1337")
        .arg("cache")
        .arg("--clear")

Review comment (performance):
```suggestion
// ignore this test for now as bat cache --clear only targets the default projects dir
```

Code after:

    // Now we expect the file to exist. If it exists, we assume contents are correct
    assert!(tmp_config_path.exists());
}

#[test]
fn config_location_from_bat_config_dir_variable() {
    bat_with_config()
        .env("BAT_CONFIG_DIR", "conf/")
        .arg("--config-file")
        .assert()
        .success()
        .stdout(predicate::str::is_match("conf/config\n").unwrap());
}

#[test]
fn config_read_arguments_from_file() {
    bat_with_config()
        .env("BAT_CONFIG_PATH", "bat.conf")
        .arg("test.txt")
        .assert()
        .success()
        .stdout(predicate::eq("dummy-pager-from-config\n").normalize());
}

// Ignore this test for now as `bat cache --clear` only targets the default cache dir.
// `bat cache --clear` must clear the `--target` dir for this test to pass.
#[cfg(unix)]
#[test]
#[ignore]
fn cache_clear() {
    let src_dir = "cache_source";
    let tmp_dir = tempdir().expect("can create temporary directory");
    let themes_filename = "themes.bin";
    let syntaxes_filename = "syntaxes.bin";
    let metadata_filename = "metadata.yaml";
    [themes_filename, syntaxes_filename, metadata_filename]
        .iter()
        .map(|filename| {
            let fp = tmp_dir.path().join(filename);
            let mut file = File::create(fp).expect("can create temporary file");
            writeln!(file, "dummy content").expect("can write to file");
        })
        .count();

    // Clear the targeted cache
    // Include the BAT_CONFIG_PATH and BAT_THEME environment variables to ensure that
    // options loaded from a config or the environment are not inserted
    // before the cache subcommand, which would break it.
    bat_with_config()
        .current_dir(Path::new(EXAMPLES_DIR).join(src_dir))