Combine iteration environment variable integration tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Peter · committed by David Peter · parent 44c0cc2 · Browse files · 1 file·+31 added−105 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+31 added−105 removed
- tests:+31 added−105 removed
Provenance
- Commit
1eafcf4- Tree
665a09c- Author
David Peter <mail@david-peter.de>- Committer
David Peter <mail@david-peter.de>- Parent
44c0cc2
1 file changed+31 added−105 removed
modified:tests/integration_tests.rs+31 added-105 removed
1036 unmodified lines1037 .assert()1038 .success();1039 }1040 1041-#[cfg(unix)]1041 #[test]1043-fn hyperfine_iteration_env_var_in_prepare_command() {1044- use tempfile::tempdir;1042+fn hyperfine_iteration_env_var_in_prepare_and_conclude_commands() {1043+ let tempdir = tempfile::tempdir().unwrap();1044+ let output_path = tempdir.path().join("iteration output.txt");1045+ let iteration = if cfg!(windows) {1046+ "%HYPERFINE_ITERATION%"1047+ } else {1048+ "$HYPERFINE_ITERATION"1049+ };1050+ let command = |phase| format!(r#"echo {phase}:{iteration} >> "iteration output.txt""#);1051 1046- let tempdir = tempdir().unwrap();1047- let output_path = tempdir.path().join("iteration_output.txt");1048-1049- // Write HYPERFINE_ITERATION value to a file during prepare1052 hyperfine()1053+ .current_dir(tempdir.path())1054 .arg("--runs=2")1055 .arg("--warmup=1")1053- .arg(format!(1054- "--prepare=echo $HYPERFINE_ITERATION >> {}",1055- output_path.to_string_lossy()1056- ))1057- .arg("echo test")1056+ .arg("--prepare")1057+ .arg(command("prepare"))1058+ .arg(command("benchmark"))1059+ .arg("--conclude")1060+ .arg(command("conclude"))1061 .assert()1062 .success();1063 1064 let contents = std::fs::read_to_string(output_path).unwrap();1062- let lines: Vec<&str> = contents.lines().collect();1063-1064- assert_eq!(lines.len(), 3);1065- assert_eq!(lines[0], "warmup-0");1066- assert_eq!(lines[1], "0");1067- assert_eq!(lines[2], "1");1065+ // cmd.exe's echo includes the space before the redirection operator.1066+ let lines: Vec<&str> = contents.lines().map(str::trim_end).collect();1067+ assert_eq!(1068+ lines,1069+ [1070+ "prepare:warmup-0",1071+ "benchmark:warmup-0",1072+ "conclude:warmup-0",1073+ "prepare:0",1074+ "benchmark:0",1075+ "conclude:0",1076+ "prepare:1",1077+ "benchmark:1",1078+ "conclude:1",1079+ ]1080+ );1081 }1069-1070-#[cfg(windows)]1071-#[test]1072-fn hyperfine_iteration_env_var_in_prepare_command() {1073- use tempfile::tempdir;1074-1075- let tempdir = tempdir().unwrap();1076- let output_path = tempdir.path().join("iteration_output.txt");1077-1078- // Write HYPERFINE_ITERATION value to a file during prepare1079- hyperfine()1080- .arg("--runs=2")1081- .arg("--warmup=1")1082- .arg(format!(1083- "--prepare=echo %HYPERFINE_ITERATION% >> {}",1084- output_path.to_string_lossy()1085- ))1086- .arg("echo test")1087- .assert()1088- .success();1089-1090- let contents = std::fs::read_to_string(output_path).unwrap();1091- let lines: Vec<String> = contents.lines().map(|l| l.trim().to_string()).collect();1092-1093- assert_eq!(lines.len(), 3);1094- assert_eq!(lines[0], "warmup-0");1095- assert_eq!(lines[1], "0");1096- assert_eq!(lines[2], "1");1097-}1098-1099-#[cfg(unix)]1100-#[test]1101-fn hyperfine_iteration_env_var_in_conclude_command() {1102- use tempfile::tempdir;1103-1104- let tempdir = tempdir().unwrap();1105- let output_path = tempdir.path().join("iteration_output.txt");1106-1107- // Write HYPERFINE_ITERATION value to a file during conclude1108- hyperfine()1109- .arg("--runs=2")1110- .arg("--warmup=1")1111- .arg(format!(1112- "--conclude=echo $HYPERFINE_ITERATION >> {}",1113- output_path.to_string_lossy()1114- ))1115- .arg("echo test")1116- .assert()1117- .success();1118-1119- let contents = std::fs::read_to_string(output_path).unwrap();1120- let lines: Vec<&str> = contents.lines().collect();1121-1122- assert_eq!(lines.len(), 3);1123- assert_eq!(lines[0], "warmup-0");1124- assert_eq!(lines[1], "0");1125- assert_eq!(lines[2], "1");1126-}1127-1128-#[cfg(windows)]1129-#[test]1130-fn hyperfine_iteration_env_var_in_conclude_command() {1131- use tempfile::tempdir;1132-1133- let tempdir = tempdir().unwrap();1134- let output_path = tempdir.path().join("iteration_output.txt");1135-1136- // Write HYPERFINE_ITERATION value to a file during conclude1137- hyperfine()1138- .arg("--runs=2")1139- .arg("--warmup=1")1140- .arg(format!(1141- "--conclude=echo %HYPERFINE_ITERATION% >> {}",1142- output_path.to_string_lossy()1143- ))1144- .arg("echo test")1145- .assert()1146- .success();1147-1148- let contents = std::fs::read_to_string(output_path).unwrap();1149- let lines: Vec<String> = contents.lines().map(|l| l.trim().to_string()).collect();1150-1151- assert_eq!(lines.len(), 3);1152- assert_eq!(lines[0], "warmup-0");1153- assert_eq!(lines[1], "0");1154- assert_eq!(lines[2], "1");1155-}