use std::fs::File;
use std::io::Write as _;
use std::path::Path;
use anyhow::Context as _;
use assert_fs::TempDir;
#[allow(dead_code)]
pub fn setup_hello_yaml(temp_dir: &TempDir) -> anyhow::Result<String> {
setup_yaml(
temp_dir,
"hello.yaml",
"
tasks:
hello:
commands:
- command: echo \"Hello, world!\"
verbose: true
description: This is a task
",
)
}
pub fn setup_yaml(temp_dir: &TempDir, file_name: &str, contents: &str) -> anyhow::Result<String> {
let config_file = temp_dir.path().join(file_name);
let mut config = File::create(config_file.clone())?;
writeln!(config, "{}", contents)?;
let config_file_path: &str = config_file
.to_str()
.with_context(|| "Failed to convert path to string")?;
Ok(config_file_path.to_string())
}
#[allow(dead_code)]
pub fn sh_path(path: &Path) -> String {
path.to_string_lossy().replace('\\', "/")
}
#[allow(dead_code)]
pub fn normalize_snapshot_text(text: &str, replacements: &[(&str, &str)]) -> String {
let mut out = text.replace("\r\n", "\n");
for (from, to) in replacements {
out = out.replace(from, to);
}
out
}