mod utils;
use crate::utils::REPO_NAME;
use anyhow::Result;
use std::fs;
use std::path::Path;
use utils::setup;
#[test]
fn test_cli_list_subcommand_without_setup() -> Result<()> {
let (_, _, command_vec, cleanup) = setup("test_cli_list_subcommand_without_setup", "list")?;
let expected_output = format!(
"Schemes are missing, run install and then try again: `{} install`",
REPO_NAME
);
let (_, stderr) = utils::run_command(command_vec).unwrap();
assert!(
stderr.contains(&expected_output),
"stdout does not contain the expected output"
);
cleanup()?;
Ok(())
}
#[test]
fn test_cli_list_subcommand_without_setup_with_custom_schemes_flag() -> Result<()> {
let test_name = "test_cli_list_subcommand_without_setup_with_custom_schemes_flag";
let (_, _, command_vec, cleanup) = setup(test_name, "list --custom-schemes")?;
let expected_output = format!(
"You don't have any local custom schemes at: data_path_{}/custom-schemes",
test_name
);
let (_, stderr) = utils::run_command(command_vec).unwrap();
assert!(
stderr.contains(&expected_output),
"stdout does not contain the expected output"
);
cleanup()?;
Ok(())
}
#[test]
fn test_cli_list_subcommand_with_setup() -> Result<()> {
let (config_path, data_path, command_vec, cleanup) =
setup("test_cli_list_subcommand_with_setup", "list")?;
let expected_output = fs::read_to_string(Path::new("fixtures/schemes.txt"))?;
utils::run_install_command(&config_path, &data_path)?;
let (stdout, _) = utils::run_command(command_vec).unwrap();
let lines: Vec<&str> = expected_output.lines().collect();
for line in lines {
assert!(
stdout.contains(line),
"stdout does not contain the expected output"
);
}
cleanup()?;
Ok(())
}
#[test]
fn test_cli_list_subcommand_with_custom() -> Result<()> {
let (_, data_path, command_vec, cleanup) =
setup("test_cli_list_subcommand_with_custom", "list")?;
let scheme_system = "base16";
let scheme_name_one = "tinted-theming";
let scheme_name_two = "tinty";
let expected_output = format!(
"{}-{}\n{}-{}",
scheme_system, scheme_name_one, scheme_system, scheme_name_two
);
let custom_scheme_path = data_path.join("custom-schemes");
fs::create_dir_all(custom_scheme_path.join(scheme_system))?;
fs::write(
custom_scheme_path.join(format!("{}/{}.yaml", scheme_system, scheme_name_one)),
"",
)?;
fs::write(
custom_scheme_path.join(format!("{}/{}.yaml", scheme_system, scheme_name_two)),
"",
)?;
let mut command_vec = command_vec.clone();
command_vec.push("--custom-schemes".to_string());
let (stdout, _) = utils::run_command(command_vec).unwrap();
let lines: Vec<&str> = expected_output.lines().collect();
for line in lines {
assert!(
stdout.contains(line),
"stdout does not contain the expected output"
);
}
cleanup()?;
Ok(())
}