diff --git a/.run_status.toml b/.run_status.toml index 8c4149a..87a12b2 100644 --- a/.run_status.toml +++ b/.run_status.toml @@ -1,7 +1,15 @@ -[last_run_incremental] +[last_run_clean] run_status = "Failure" -lines_parsed = 12 +lines_parsed = 20 + +[last_run_clean.run_duration] +secs = 20 +nanos = 321146474 + +[last_run_incremental] +run_status = "Success" +lines_parsed = 19 [last_run_incremental.run_duration] -secs = 13 -nanos = 274357405 +secs = 9 +nanos = 407112483 diff --git a/run b/run new file mode 100644 index 0000000..92ac197 --- /dev/null +++ b/run @@ -0,0 +1,22 @@ +2025-03-19T13:50:48.031029Z  INFO cargo_tarpaulin::config: Creating config +2025-03-19T13:50:48.086450Z  INFO cargo_tarpaulin: Running Tarpaulin +2025-03-19T13:50:48.086466Z  INFO cargo_tarpaulin: Building project +2025-03-19T13:50:48.086469Z  INFO cargo_tarpaulin::cargo: Cleaning project +2025-03-19T13:51:01.196213Z  INFO cargo_tarpaulin::process_handling::linux: Launching test +2025-03-19T13:51:01.196247Z  INFO cargo_tarpaulin::process_handling: running /home/beffroi/Documents/Git/rust_autobadges/target/debug/deps/rust_autobadges-88a057f7e5bc03ef + +running 4 tests +test test::test_badge_writing ... ignored +test test::test_coverage_parsing ... ignored +test test::test_structs ... ignored +test test::test_version_parsing ... ignored + +test result: ok. 0 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 0.00s + +2025-03-19T13:51:07.936086Z  INFO cargo_tarpaulin::report: Coverage Results: +|| Uncovered Lines: +|| src/main.rs: 46, 48-49, 100-101, 105-110, 116-117, 119-120, 124, 127, 133-136, 141, 146-150, 152, 158-162, 169-172, 176-178, 180, 248-249, 251-252, 254-255, 261, 266, 268-269, 272, 278-279, 282-283, 285, 289, 291-295, 299, 304, 310-312, 314-315, 319-321, 324, 329-331, 334-335, 337-339, 341, 344-345, 349-352, 354-356, 358, 380-381, 385-386, 388-390, 398-399, 402, 408, 412-414, 416, 418, 427, 435, 437-441, 444-445, 450, 458-467, 469, 473-474, 479, 481-482, 484, 486-487, 489-490, 492, 494-495, 499-501, 503, 506-507, 509-512, 515, 517-518, 520, 539, 546-547, 550-552 +|| Tested/Total Lines: +|| src/main.rs: 0/163 +0.00% +|| +0.00% coverage, 0/163 lines covered, +0.00% change in coverage diff --git a/run_err b/run_err new file mode 100644 index 0000000..015e224 --- /dev/null +++ b/run_err @@ -0,0 +1,58 @@ + Compiling proc-macro2 v1.0.94 + Compiling unicode-ident v1.0.18 + Compiling libc v0.2.170 + Compiling serde v1.0.219 + Compiling autocfg v1.4.0 + Compiling utf8parse v0.2.2 + Compiling parking_lot_core v0.9.10 + Compiling anstyle-parse v0.2.6 + Compiling anstyle-query v1.1.2 + Compiling equivalent v1.0.2 + Compiling hashbrown v0.15.2 + Compiling cfg-if v1.0.0 + Compiling colorchoice v1.0.3 + Compiling is_terminal_polyfill v1.70.1 + Compiling memchr v2.7.4 + Compiling scopeguard v1.2.0 + Compiling anstyle v1.0.10 + Compiling lock_api v0.4.12 + Compiling portable-atomic v1.11.0 + Compiling quote v1.0.39 + Compiling syn v2.0.100 + Compiling smallvec v1.14.0 + Compiling aho-corasick v1.1.3 + Compiling indexmap v2.8.0 + Compiling anstream v0.6.18 + Compiling regex-syntax v0.8.5 + Compiling anyhow v1.0.94 + Compiling once_cell v1.20.3 + Compiling unicode-width v0.2.0 + Compiling winnow v0.7.4 + Compiling strsim v0.11.1 + Compiling clap_lex v0.7.4 + Compiling heck v0.5.0 + Compiling clap_builder v4.5.31 + Compiling console v0.15.11 + Compiling regex-automata v0.4.9 + Compiling parking_lot v0.12.3 + Compiling signal-hook-registry v1.4.2 + Compiling socket2 v0.5.8 + Compiling mio v1.0.3 + Compiling bytes v1.10.1 + Compiling pin-project-lite v0.2.16 + Compiling number_prefix v0.4.0 + Compiling xshell-macros v0.2.7 + Compiling regex v1.11.1 + Compiling xshell v0.2.7 + Compiling serde_derive v1.0.219 + Compiling clap_derive v4.5.28 + Compiling tokio-macros v2.5.0 + Compiling indicatif v0.17.11 + Compiling tokio v1.44.1 + Compiling clap v4.5.31 + Compiling toml_datetime v0.6.8 + Compiling serde_spanned v0.6.8 + Compiling toml_edit v0.22.24 + Compiling toml v0.8.20 + Compiling rust_autobadges v0.1.0 (/home/beffroi/Documents/Git/rust_autobadges) + Finished `test` profile [unoptimized + debuginfo] target(s) in 12.96s diff --git a/src/main.rs b/src/main.rs index 2ac6d2b..c02ac3e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -66,7 +66,7 @@ struct CurrentRunStats { /// A (very) simple run status enum RunStatus { /// The last run was a succes - Succes, + Success, #[default] /// The tests failed to run Failure, @@ -83,6 +83,55 @@ enum RunType { Clean, } +/// Enum guessing at which state the program is +enum RunState { + /// The program is compiling and the inner field is our guess as to what + Compiling(String), + /// The program is running the tests + Testing(String), + /// The program is doing code coverage + Coverage, + /// The run is finished + Finished, +} + +impl RunState { + /// Create a new state + fn new() -> Self { + RunState::Compiling(String::new()) + } + + /// Output a human readable status from the current state + fn status(&self) -> String { + match self { + RunState::Compiling(guess) => format!("Compiling {}", guess), + RunState::Testing(test) => format!("Testing: {}", test), + RunState::Coverage => "Coverage".to_string(), + RunState::Finished => "Finished".to_string(), + } + } + + /// Update the status with the new info + // TODO: The coverage and some run info being dependent on this update, the method should be moved + fn update(&mut self, ingest: &str) -> anyhow::Result<()> { + match self { + RunState::Compiling(_) => { + if !ingest.starts_with("Compiling") { + *self = RunState::Testing(String::new()); + } + } + RunState::Testing(_) => { + if !ingest.starts_with("Testing") { + *self = RunState::Coverage; + } + } + RunState::Coverage => *self = RunState::Finished, + RunState::Finished => (), + } + Ok(()) + } +} + impl CurrentRunStats { /// Generate a new run with the current context fn from_last_run_with_context(last_run: LastRuns, args: &CLIArgs) -> Self { @@ -255,10 +304,6 @@ fn load_status(args: &CLIArgs) -> LastRuns { } /// Run the coverage functions -// FORMAT: Compiling strsim v0.11.1 -// FORMAT: Finished `test` profile [unoptimized + debuginfo] target(s) in 6.87s -// FORMAT: 2025-03-10T20:00:03.543721Z INFO cargo_tarpaulin::process_handling::linux: Launching test -// FORMAT: 2025-03-10T20:00:08.030646Z INFO cargo_tarpaulin::report: Coverage Results: // #[coverage(off)] // No real coverage can be done as it would recurse indefinitely fn run_coverage( _sh: &Shell, @@ -275,15 +320,13 @@ fn run_coverage( // TODO: Update the status with basic parsing from the output // (compiling (), linking (), running tests (), etc..) - // cmd!(sh, "cargo tarpaulin").quiet().ignore_stdout().run()?; let mut args_tarpaulin = vec!["tarpaulin", "-o", "html"]; if args.skip_clean { args_tarpaulin.push("--skip-clean"); } let rt = runtime::Builder::new_current_thread() - .enable_time() - .enable_io() + .enable_all() .build() .expect("[tokio] Failed to create runtime"); @@ -293,66 +336,59 @@ fn run_coverage( // Specify that we want the command's standard output piped back to us. cmd.stdout(std::process::Stdio::piped()); + cmd.stderr(std::process::Stdio::piped()); - // // FORMAT: 84.78% coverage, 78/92 lines covered, -15.22% change in coverage - // let mut child = cmd.spawn().expect("Failed to spawn command"); - - // let stdout = child - // .stdout - // .take() - // .expect("Child did not have a handle to stdout"); - - // let reader = tokio::io::BufReader::new(stdout).split(0xA); - - // // Ensure the child process is spawned in the runtime so it can - // // make progress on its own while we await for any output. - // tokio::task::spawn(async move { - // let _status = child - // .wait() - // .await - // .expect("Child process encountered an error"); - // // sleep(Duration::from_millis(100)).await; - // // println!("Child status was: {}", status); - // }); - rt.block_on(async { + let run_info = rt.block_on(async { let mut child = cmd.spawn().expect("Failed to spawn command"); + let mut state = RunState::new(); let stdout = child .stdout .take() .expect("Child did not have a handle to stdout"); - - let mut reader = tokio::io::BufReader::new(stdout).split(0xA); - while let Ok(Some(line)) = reader.next_segment().await { - // progress_spinner.set_message( - // // String::from_utf8(line).unwrap_or_default(), // "No", - // "no", - // ); - } - // parse_all_line_sync(args, run_info, reader, progress_spinner, progress_bar) - // .await - // .expect("Impossible to parse line"); + // let stderr = child + // .stderr + // .take() + // .expect("Child did not have a handle to stderr"); + let reader = tokio::io::BufReader::new(stdout).split(0xA); + parse_all_lines_sync( + args, + run_info, + reader, + progress_spinner, + progress_bar, + &mut state, + ) + .await + .expect("Impossible to parse line"); + run_info.current_run.run_status = if let Ok(output) = child.wait_with_output().await { + if output.status.success() { + RunStatus::Success + } else { + RunStatus::Failure + } + } else { + RunStatus::Success + }; + run_info }); - // if !args.no_test { - // // Only write the test badge if it was asked for - // // TODO: isolate in it's own command or use the wrapper struct to avoid multiple write badge - // match &output.status.success() { - // true => write_badge("test", "passing", &args.success_color, "test", args)?, - // false => write_badge("test", "failing", &args.failing_color, "test", args)?, - // }; - // } - // update_final_coverage( - // args, - // run_info, - // started, - // progress_spinner, - // progress_bar, - // output, - // )?; + if !args.no_test { + // Only write the test badge if it was asked for + // TODO: isolate in it's own command or use the wrapper struct to avoid multiple write badge + match run_info.current_run.run_status { + RunStatus::Success => { + write_badge("test", "passing", &args.success_color, "test", args)? + } + RunStatus::Failure => { + write_badge("test", "failing", &args.failing_color, "test", args)? + } + }; + } + + // update_final_coverage(args, run_info, started, progress_spinner, progress_bar)?; run_info.current_run.run_duration = started.elapsed(); - run_info.current_run.lines_parsed = 12; // TODO: Update lines Ok(()) } @@ -388,62 +424,58 @@ fn create_progress_spinner(pb: ProgressBar, multiprogress: &MultiProgress) -> Pr let progress_spinner = multiprogress.add(pb); progress_spinner.enable_steady_tick(Duration::from_millis(100)); - progress_spinner.with_message(format!( - "{:>10} Mesuring coverage...", - style("[Coverage]").green().bold() - )) + progress_spinner.with_message(formatted_width("[Coverage]", "Mesuring coverage...")) } -/// Mod -async fn parse_all_line_sync( +/// Output the standard width of the program +fn formatted_width(cmd: &str, text: &str) -> String { + format!("{:>10} {}", style(cmd).green().bold(), text,) +} + +/// Parse evert tarpaulin to try and guess what is happening +// FORMAT: Compiling strsim v0.11.1 +// FORMAT: Finished `test` profile [unoptimized + debuginfo] target(s) in 6.87s +// FORMAT: 2025-03-10T20:00:03.543721Z INFO cargo_tarpaulin::process_handling::linux: Launching test +// FORMAT: 2025-03-10T20:00:08.030646Z INFO cargo_tarpaulin::report: Coverage Results: +// 2025-03-19T13:50:48.031029Z  INFO cargo_tarpaulin::config: Creating config +// 2025-03-19T13:50:48.086450Z  INFO cargo_tarpaulin: Running Tarpaulin +// 2025-03-19T13:50:48.086466Z  INFO cargo_tarpaulin: Building project +// 2025-03-19T13:50:48.086469Z  INFO cargo_tarpaulin::cargo: Cleaning project +// 2025-03-19T13:51:01.196213Z  INFO cargo_tarpaulin::process_handling::linux: Launching test +async fn parse_all_lines_sync( args: &CLIArgs, run_info: &mut CurrentRunStats, mut reader: tokio::io::Split>, progress_spinner: ProgressBar, progress_bar: ProgressBar, + state: &mut RunState, ) -> anyhow::Result<()> { + let _ = args; let mut lines_parsed = 0; - loop { - let res = reader.next_segment().await; - // // let new = min(built + 1, to_build); - // let new = if built < to_build { - // built + 1 - // } else { - // to_build += 1; - // pb.set_length(to_build); - // built + 1 - // }; - // built = new; - // pb.set_position(new); - // current_run.lines_parsed += 1; - // - if let Err(e) = res { - return Err(anyhow::anyhow!("[CORE] Runtime error : {}", e)); - } else if let Ok(Some(line)) = res { - progress_bar.inc(1); - lines_parsed += 1; - progress_spinner.set_message( - String::from_utf8(line).unwrap_or_default(), // "No", - ); - } else { - break; - } + while let Ok(Some(line)) = reader.next_segment().await { + let line = String::from_utf8(line).unwrap_or_default(); + progress_bar.inc(1); + lines_parsed += 1; + state.update(&line)?; + progress_spinner.set_message(state.status()); } run_info.current_run.lines_parsed = lines_parsed; Ok(()) } /// Update the final coverage from the final output +// FORMAT: 84.78% coverage, 78/92 lines covered, -15.22% change in coverage +// TODO: Add this into the line parser fn update_final_coverage( args: &CLIArgs, run_info: &mut CurrentRunStats, started: Instant, progress_spinner: ProgressBar, progress_bar: ProgressBar, - output: std::process::Output, + run: std::process::Output, ) -> Result<(), anyhow::Error> { - let test = String::from_utf8(output.stdout)?; + let test = String::from_utf8(run.stdout)?; let re = Regex::new(r"(\d+.\d+)% coverage, ").unwrap(); let coverage = re.captures(&test); if let Some(c) = coverage { @@ -469,7 +501,7 @@ fn update_final_coverage( style("[Coverage]").bold().green(), started.elapsed().as_secs_f32() )); - run_info.current_run.run_status = RunStatus::Succes; + run_info.current_run.run_status = RunStatus::Success; } else { write_badge("test-coverage", "N/A", "red", "coverage", args)?; progress_spinner.finish_with_message(format!(