Skip to content

Commit b01fdde

Browse files
committed
Show progress of dev check
1 parent 78a8553 commit b01fdde

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/dev/check.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ fn check_unexpected_files(dir: &str, allowed_rust_files: &HashSet<PathBuf>) -> R
161161
}
162162

163163
fn check_exercises_unsolved(info_file: &InfoFile, cmd_runner: &CmdRunner) -> Result<()> {
164-
println!(
165-
"Running all exercises to check that they aren't already solved. This may take a while…\n",
166-
);
164+
let mut stdout = io::stdout().lock();
165+
stdout.write_all(b"Running all exercises to check that they aren't already solved...\n")?;
166+
167167
thread::scope(|s| {
168168
let handles = info_file
169169
.exercises
@@ -180,6 +180,11 @@ fn check_exercises_unsolved(info_file: &InfoFile, cmd_runner: &CmdRunner) -> Res
180180
})
181181
.collect::<Vec<_>>();
182182

183+
let n_handles = handles.len();
184+
write!(stdout, "Progress: 0/{n_handles}")?;
185+
stdout.flush()?;
186+
let mut handle_num = 1;
187+
183188
for (exercise_name, handle) in handles {
184189
let Ok(result) = handle.join() else {
185190
bail!("Panic while trying to run the exericse {exercise_name}");
@@ -192,7 +197,12 @@ fn check_exercises_unsolved(info_file: &InfoFile, cmd_runner: &CmdRunner) -> Res
192197
Ok(false) => (),
193198
Err(e) => return Err(e),
194199
}
200+
201+
write!(stdout, "\rProgress: {handle_num}/{n_handles}")?;
202+
stdout.flush()?;
203+
handle_num += 1;
195204
}
205+
stdout.write_all(b"\n")?;
196206

197207
Ok(())
198208
})
@@ -225,7 +235,9 @@ fn check_solutions(
225235
info_file: &InfoFile,
226236
cmd_runner: &CmdRunner,
227237
) -> Result<()> {
228-
println!("Running all solutions. This may take a while…\n");
238+
let mut stdout = io::stdout().lock();
239+
stdout.write_all(b"Running all solutions...\n")?;
240+
229241
thread::scope(|s| {
230242
let handles = info_file
231243
.exercises
@@ -261,6 +273,11 @@ fn check_solutions(
261273
.arg("always")
262274
.stdin(Stdio::null());
263275

276+
let n_handles = handles.len();
277+
write!(stdout, "Progress: 0/{n_handles}")?;
278+
stdout.flush()?;
279+
let mut handle_num = 1;
280+
264281
for (exercise_info, handle) in info_file.exercises.iter().zip(handles) {
265282
let Ok(check_result) = handle.join() else {
266283
bail!(
@@ -282,15 +299,21 @@ fn check_solutions(
282299
}
283300
SolutionCheck::MissingOptional => (),
284301
SolutionCheck::RunFailure { output } => {
285-
io::stderr().lock().write_all(&output)?;
302+
stdout.write_all(b"\n\n")?;
303+
stdout.write_all(&output)?;
286304
bail!(
287305
"Running the solution of the exercise {} failed with the error above",
288306
exercise_info.name,
289307
);
290308
}
291309
SolutionCheck::Err(e) => return Err(e),
292310
}
311+
312+
write!(stdout, "\rProgress: {handle_num}/{n_handles}")?;
313+
stdout.flush()?;
314+
handle_num += 1;
293315
}
316+
stdout.write_all(b"\n")?;
294317

295318
let handle = s.spawn(move || check_unexpected_files("solutions", &sol_paths));
296319

0 commit comments

Comments
 (0)