mod utils;
use std::fs;
use crate::utils::{setup, write_to_file, CURRENT_SCHEME_FILE_NAME, REPO_NAME};
use anyhow::{ensure, Result};
use utils::ARTIFACTS_DIR;
#[test]
fn test_cli_init_subcommand_without_setup() -> Result<()> {
let (_, data_path, command_vec, _temp_dir) =
setup("test_cli_init_subcommand_without_setup", "init")?;
let expected_output = format!(
"Failed to initialize, config files seem to be missing. Try applying a theme first with `{REPO_NAME} apply <SCHEME_NAME>`.",
);
let (_, stderr) = utils::run_command(&command_vec, &data_path, true)?;
ensure!(
stderr.contains(&expected_output),
"Expected stderr to contain: {expected_output}\nGot: {stderr}"
);
Ok(())
}
#[test]
fn test_cli_init_subcommand_with_setup() -> Result<()> {
let (_, data_path, command_vec, _temp_dir) =
setup("test_cli_init_subcommand_with_setup", "init")?;
let (stdout, _) = utils::run_command(&command_vec, &data_path, true)?;
ensure!(stdout.is_empty(), "Expected empty stdout, got: {stdout}");
Ok(())
}
#[test]
fn test_cli_init_subcommand_with_config_default_scheme() -> Result<()> {
let (config_path, data_path, command_vec, _temp_dir) = setup(
"test_cli_init_subcommand_with_config_default_scheme",
"init",
)?;
let scheme_name = "base16-mocha";
let config_content = format!("default-scheme = \"{scheme_name}\"");
write_to_file(&config_path, config_content.as_str())?;
let (stdout, stderr) = utils::run_command(&command_vec, &data_path, true)?;
let expected_scheme_name =
fs::read_to_string(data_path.join(ARTIFACTS_DIR).join(CURRENT_SCHEME_FILE_NAME))?;
ensure!(stdout.is_empty(), "Expected empty stdout, got: {stdout}");
ensure!(stderr.is_empty(), "Expected empty stderr, got: {stderr}");
ensure!(
scheme_name == expected_scheme_name,
"scheme_name does not contain the expected output"
);
Ok(())
}