Skip to content

Commit

Permalink
fix(runner): control cargo-codspeed running environment
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Dec 4, 2023
1 parent 95fbdf0 commit 5d15626
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion src/runner/valgrind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ lazy_static! {
};
}

fn get_bench_command(config: &Config) -> String {
let bench_command = &config.command;
bench_command
// Fixes a compatibility issue with cargo 1.66+ running directly under valgrind <3.20
.replace("cargo codspeed", "cargo-codspeed")
}

pub fn measure(config: &Config, profile_folder: &Path) -> Result<()> {
debug!("profile dir: {}", profile_folder.display());

Expand Down Expand Up @@ -82,7 +89,7 @@ pub fn measure(config: &Config, profile_folder: &Path) -> Result<()> {
.arg(format!("--log-file={}", log_path.to_str().unwrap()).as_str());

// Set the command to execute
cmd.args(["sh", "-c", config.command.as_str()]);
cmd.args(["sh", "-c", get_bench_command(config).as_str()]);

debug!("cmd: {:?}", cmd);
let status = cmd
Expand All @@ -94,3 +101,38 @@ pub fn measure(config: &Config, profile_folder: &Path) -> Result<()> {

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_get_bench_command_cargo() {
let config = Config {
command: "cargo codspeed bench".into(),
..Config::test()
};
assert_eq!(get_bench_command(&config), "cargo-codspeed bench");
}

#[test]
fn test_get_bench_command_multiline() {
let config = Config {
command: r#"
cargo codspeed bench --features "foo bar"
pnpm vitest bench "my-app"
pytest tests/ --codspeed
"#
.into(),
..Config::test()
};
assert_eq!(
get_bench_command(&config),
r#"
cargo-codspeed bench --features "foo bar"
pnpm vitest bench "my-app"
pytest tests/ --codspeed
"#
);
}
}

0 comments on commit 5d15626

Please sign in to comment.