Skip to content
Myr

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

1 file+31 added−105 removed

modified:tests/integration_tests.rs+31 added-105 removed
1036 unmodified lines
1037 .assert()1038 .success();1039}10401041#[cfg(unix)]1041#[test]1043fn hyperfine_iteration_env_var_in_prepare_command() {1044 use tempfile::tempdir;1042fn 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""#);10511046 let tempdir = tempdir().unwrap();1047 let output_path = tempdir.path().join("iteration_output.txt");10481049 // 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();10631064 let contents = std::fs::read_to_string(output_path).unwrap();1062 let lines: Vec<&str> = contents.lines().collect();10631064 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}10691070#[cfg(windows)]1071#[test]1072fn hyperfine_iteration_env_var_in_prepare_command() {1073 use tempfile::tempdir;10741075 let tempdir = tempdir().unwrap();1076 let output_path = tempdir.path().join("iteration_output.txt");10771078 // 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();10891090 let contents = std::fs::read_to_string(output_path).unwrap();1091 let lines: Vec<String> = contents.lines().map(|l| l.trim().to_string()).collect();10921093 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}10981099#[cfg(unix)]1100#[test]1101fn hyperfine_iteration_env_var_in_conclude_command() {1102 use tempfile::tempdir;11031104 let tempdir = tempdir().unwrap();1105 let output_path = tempdir.path().join("iteration_output.txt");11061107 // 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();11181119 let contents = std::fs::read_to_string(output_path).unwrap();1120 let lines: Vec<&str> = contents.lines().collect();11211122 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}11271128#[cfg(windows)]1129#[test]1130fn hyperfine_iteration_env_var_in_conclude_command() {1131 use tempfile::tempdir;11321133 let tempdir = tempdir().unwrap();1134 let output_path = tempdir.path().join("iteration_output.txt");11351136 // 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();11471148 let contents = std::fs::read_to_string(output_path).unwrap();1149 let lines: Vec<String> = contents.lines().map(|l| l.trim().to_string()).collect();11501151 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}