MCPcopy Create free account
hub / github.com/PerroEngine/Perro / test_command

Function test_command

perro_source/devtools/perro_cli/src/script_tests.rs:9–56  ·  view source on GitHub ↗
(args: &[String], cwd: &Path)

Source from the content-addressed store, hash-verified

7use std::process::Command;
8
9pub(crate) fn test_command(args: &[String], cwd: &Path) -> Result<(), String> {
10 let project_dir = parse_flag_value(args, "--path")
11 .map(|p| resolve_local_path(&p, cwd))
12 .or_else(|| find_project_root(cwd))
13 .unwrap_or_else(|| cwd.to_path_buf());
14 let project_dir = project_dir.canonicalize().unwrap_or(project_dir);
15 if !project_dir.join("project.toml").exists() {
16 return Err(format!(
17 "invalid --path `{}` for test. Use project root (directory containing project.toml).",
18 project_dir.display()
19 ));
20 }
21
22 log_step("Syncing Test Scripts");
23 ensure_source_overrides(&project_dir)
24 .map_err(|err| format!("failed to refresh source overrides: {err}"))?;
25 sync_scripts(&project_dir).map_err(|err| format!("failed to sync scripts: {err}"))?;
26 log_done("Test Scripts Synced");
27
28 log_note("Running Script Tests");
29 let project_cfg = load_project_toml(&project_dir)
30 .map_err(|err| format!("failed to load project.toml: {err}"))?;
31 let scripts_crate = project_dir.join(".perro").join("scripts");
32 let target_dir = project_dir.join("target");
33 let mut cmd = Command::new("cargo");
34 cmd.arg("test")
35 .env("CARGO_TARGET_DIR", &target_dir)
36 .current_dir(&scripts_crate);
37 if project_cfg.steam.enabled {
38 cmd.arg("--features").arg("steamworks");
39 }
40 cmd.args(passthrough_args(args));
41
42 let status = cmd.status().map_err(|err| {
43 format!(
44 "failed to run cargo test from {}: {err}",
45 scripts_crate.display()
46 )
47 })?;
48 if !status.success() {
49 return Err(format!(
50 "cargo test failed with exit code {:?}",
51 status.code()
52 ));
53 }
54 log_done("Script Tests Finished");
55 Ok(())
56}
57
58fn passthrough_args(args: &[String]) -> &[String] {
59 let Some(idx) = args.iter().position(|arg| arg == "--") else {

Callers 1

mainFunction · 0.85

Calls 11

find_project_rootFunction · 0.85
log_stepFunction · 0.85
ensure_source_overridesFunction · 0.85
sync_scriptsFunction · 0.85
log_doneFunction · 0.85
log_noteFunction · 0.85
load_project_tomlFunction · 0.85
joinMethod · 0.80
parse_flag_valueFunction · 0.70
resolve_local_pathFunction · 0.70
passthrough_argsFunction · 0.70

Tested by

no test coverage detected