From efa9f0e63dadde9cdd4e401a08ffc04812d84785 Mon Sep 17 00:00:00 2001 From: Keith Hall Date: Mon, 24 Nov 2025 22:16:51 +0200 Subject: [PATCH] add integration test to prove that building the cache finds all contexts --- tests/integration_tests.rs | 46 +++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index 27ee6add..5dc35d6e 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1599,7 +1599,7 @@ Clearing metadata file ... okay", #[cfg(unix)] #[test] -fn cache_build() { +fn cache_build_blank() { let src_dir = "cache_source"; let tmp_dir = tempdir().expect("can create temporary directory"); let tmp_themes_path = tmp_dir.path().join("themes.bin"); @@ -1642,6 +1642,50 @@ Writing metadata to folder .* ... okay", assert!(tmp_metadata_path.exists()); } +#[cfg(unix)] +#[test] +fn cache_build() { + let src_dir = "cache_source"; + let tmp_dir = tempdir().expect("can create temporary directory"); + let tmp_themes_path = tmp_dir.path().join("themes.bin"); + let tmp_syntaxes_path = tmp_dir.path().join("syntaxes.bin"); + let tmp_acknowledgements_path = tmp_dir.path().join("acknowledgements.bin"); + let tmp_metadata_path = tmp_dir.path().join("metadata.yaml"); + + // Build the 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)) + .env("BAT_CONFIG_PATH", "bat.conf") + .env("BAT_THEME", "1337") + .arg("cache") + .arg("--build") + // removed --blank + .arg("--source") + .arg(".") + .arg("--target") + .arg(tmp_dir.path().to_str().unwrap()) + .arg("--acknowledgements") + .assert() + .success() + .stdout( + predicate::str::is_match( + "Writing theme set to .*/themes.bin ... okay\nWriting syntax set to .*/syntaxes.bin ... okay\nWriting acknowledgements to .*/acknowledgements.bin ... okay\nWriting metadata to folder .* ... okay", + ) + .unwrap(), + ) + .stdout(predicate::str::contains("Some referenced contexts could not be found!").not()) + ; + + // Now we expect the files to exist. If they exist, we assume contents are correct + assert!(tmp_themes_path.exists()); + assert!(tmp_syntaxes_path.exists()); + assert!(tmp_acknowledgements_path.exists()); + assert!(tmp_metadata_path.exists()); +} + #[test] fn utf16() { // The output will be converted to UTF-8 with the leading UTF-16