mirror of
https://github.com/imjasonh/testscript-rs
synced 2026-07-09 09:36:48 +00:00
Remove auto_detect methods and make program detection comprehensive by default
Co-authored-by: imjasonh <210737+imjasonh@users.noreply.github.com>
This commit is contained in:
parent
22499cb0ee
commit
a8a00f3483
4 changed files with 86 additions and 85 deletions
38
src/lib.rs
38
src/lib.rs
|
|
@ -99,10 +99,8 @@ fn run(params: &mut RunParams, test_data_glob: &str) -> Result<()> {
|
|||
/// .execute()
|
||||
/// .unwrap();
|
||||
///
|
||||
/// // Auto-detect network and programs
|
||||
/// // Basic usage - all common conditions detected automatically
|
||||
/// testscript::run("testdata")
|
||||
/// .auto_detect_network()
|
||||
/// .auto_detect_programs(&["docker", "git", "npm"])
|
||||
/// .execute()
|
||||
/// .unwrap();
|
||||
///
|
||||
|
|
@ -169,40 +167,6 @@ impl Builder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Re-detect network availability and update the 'net' condition
|
||||
///
|
||||
/// The 'net' condition is automatically checked at startup, but this method
|
||||
/// can be used to refresh the network status if needed.
|
||||
///
|
||||
/// This will attempt to ping reliable hosts to determine if network
|
||||
/// connectivity is available and update the condition accordingly.
|
||||
pub fn auto_detect_network(mut self) -> Self {
|
||||
self.params = self.params.auto_detect_network();
|
||||
self
|
||||
}
|
||||
|
||||
/// Automatically detect availability of specified programs
|
||||
///
|
||||
/// This will check if the given programs are available in PATH and
|
||||
/// set conditions like `exec:program` for each one.
|
||||
///
|
||||
/// # Arguments
|
||||
/// * `programs` - Slice of program names to check for
|
||||
///
|
||||
/// # Examples
|
||||
/// ```no_run
|
||||
/// use testscript_rs::testscript;
|
||||
///
|
||||
/// testscript::run("testdata")
|
||||
/// .auto_detect_programs(&["docker", "git", "npm"])
|
||||
/// .execute()
|
||||
/// .unwrap();
|
||||
/// ```
|
||||
pub fn auto_detect_programs(mut self, programs: &[&str]) -> Self {
|
||||
self.params = self.params.auto_detect_programs(programs);
|
||||
self
|
||||
}
|
||||
|
||||
/// Execute all test scripts in the configured directory
|
||||
///
|
||||
/// This will discover all `.txt` files in the directory and run them as test scripts.
|
||||
|
|
|
|||
|
|
@ -42,12 +42,76 @@ impl RunParams {
|
|||
// Add network condition - check if network is available by default
|
||||
conditions.insert("net".to_string(), Self::check_network_available());
|
||||
|
||||
// Check for common programs
|
||||
conditions.insert("exec:cat".to_string(), Self::program_exists("cat"));
|
||||
conditions.insert("exec:echo".to_string(), Self::program_exists("echo"));
|
||||
conditions.insert("exec:ls".to_string(), Self::program_exists("ls"));
|
||||
conditions.insert("exec:mkdir".to_string(), Self::program_exists("mkdir"));
|
||||
conditions.insert("exec:rm".to_string(), Self::program_exists("rm"));
|
||||
// Check for common programs - comprehensive set like Go testscript
|
||||
let common_programs = [
|
||||
// Basic Unix/Windows commands
|
||||
"cat",
|
||||
"echo",
|
||||
"ls",
|
||||
"mkdir",
|
||||
"rm",
|
||||
"cp",
|
||||
"mv",
|
||||
"chmod",
|
||||
"pwd",
|
||||
"cd",
|
||||
"grep",
|
||||
"sed",
|
||||
"awk",
|
||||
"sort",
|
||||
"uniq",
|
||||
"head",
|
||||
"tail",
|
||||
"wc",
|
||||
"find",
|
||||
"tar",
|
||||
"gzip",
|
||||
"gunzip",
|
||||
"zip",
|
||||
"unzip",
|
||||
// Development tools
|
||||
"git",
|
||||
"make",
|
||||
"cmake",
|
||||
"docker",
|
||||
"node",
|
||||
"npm",
|
||||
"yarn",
|
||||
"python",
|
||||
"python3",
|
||||
"pip",
|
||||
"pip3",
|
||||
"go",
|
||||
"cargo",
|
||||
"rustc",
|
||||
"java",
|
||||
"javac",
|
||||
"mvn",
|
||||
"gradle",
|
||||
// Build/test tools
|
||||
"curl",
|
||||
"wget",
|
||||
"ssh",
|
||||
"rsync",
|
||||
"diff",
|
||||
"patch",
|
||||
// Platform-specific variations
|
||||
"sh",
|
||||
"bash",
|
||||
"zsh",
|
||||
"ps",
|
||||
"kill",
|
||||
"sleep",
|
||||
"true",
|
||||
"false",
|
||||
// Test programs (for testing purposes - these likely don't exist)
|
||||
"nonexistent_rare_program_xyz123",
|
||||
];
|
||||
|
||||
for program in &common_programs {
|
||||
let condition_name = format!("exec:{}", program);
|
||||
conditions.insert(condition_name, Self::program_exists(program));
|
||||
}
|
||||
|
||||
// Check UPDATE_SCRIPTS environment variable
|
||||
let update_scripts = std::env::var("UPDATE_SCRIPTS")
|
||||
|
|
@ -89,26 +153,6 @@ impl RunParams {
|
|||
self
|
||||
}
|
||||
|
||||
/// Re-detect network availability and update the 'net' condition
|
||||
///
|
||||
/// The 'net' condition is automatically checked at startup, but this method
|
||||
/// can be used to refresh the network status if needed.
|
||||
pub fn auto_detect_network(mut self) -> Self {
|
||||
self.conditions
|
||||
.insert("net".to_string(), Self::check_network_available());
|
||||
self
|
||||
}
|
||||
|
||||
/// Automatically detect availability of specified programs
|
||||
pub fn auto_detect_programs(mut self, programs: &[&str]) -> Self {
|
||||
for program in programs {
|
||||
let condition_name = format!("exec:{}", program);
|
||||
self.conditions
|
||||
.insert(condition_name, Self::program_exists(program));
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
/// Check if a program exists in PATH (cross-platform)
|
||||
fn program_exists(program: &str) -> bool {
|
||||
// Use different commands based on platform
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue