From 5bb0ca607e7cd95cc4af370dbda04e9e433c30d7 Mon Sep 17 00:00:00 2001 From: BrettMayson Date: Mon, 13 May 2024 21:10:32 -0600 Subject: [PATCH] new: don't write ci annotations (#695) --- bin/src/commands/new/mod.rs | 52 +++++++++++++++++++++++++++++-------- bin/src/lib.rs | 5 +++- bin/tests/build.rs | 15 ++++++----- bin/tests/new.rs | 10 +++++++ 4 files changed, 64 insertions(+), 18 deletions(-) create mode 100644 bin/tests/new.rs diff --git a/bin/src/commands/new/mod.rs b/bin/src/commands/new/mod.rs index 3008a492..1161d869 100644 --- a/bin/src/commands/new/mod.rs +++ b/bin/src/commands/new/mod.rs @@ -37,7 +37,9 @@ pub fn cli() -> Command { pub fn execute(matches: &ArgMatches) -> Result { let mut report = Report::new(); - if !std::io::stdin().is_terminal() { + let test_mode = matches.get_flag("in-test"); + + if !test_mode && !std::io::stdin().is_terminal() { report.error(TerminalNotInput::code()); return Ok(report); } @@ -52,20 +54,48 @@ pub fn execute(matches: &ArgMatches) -> Result { } println!("Example: Advanced Banana Environment"); - let full_name: String = Input::new().with_prompt("Project Name").interact_text()?; + let full_name: String = if test_mode { + String::from("Advanced Banana Environment") + } else { + Input::new().with_prompt("Project Name").interact_text()? + }; println!("Example: ABE Team"); - let author: String = Input::new().with_prompt("Author").interact_text()?; + let author: String = if test_mode { + String::from("ABE Team") + } else { + Input::new().with_prompt("Author").interact_text()? + }; println!("Example: abe"); - let prefix: String = Input::new().with_prompt("Prefix").interact_text()?; - - let mainprefix: String = Input::new() - .with_prompt("Main Prefix") - .with_initial_text("z") - .interact_text()?; - - let license = Licenses::select(&author); + let prefix: String = if test_mode { + String::from("abe") + } else { + Input::new().with_prompt("Prefix").interact_text()? + }; + + let mainprefix: String = if test_mode { + String::from("z") + } else { + Input::new() + .with_prompt("Main Prefix") + .with_initial_text("z") + .interact_text()? + }; + + let license = if test_mode { + Some( + String::from_utf8( + Licenses::get("apl-sa.txt") + .expect("apl-sa should exist") + .data + .to_vec(), + ) + .expect("license should be utf8"), + ) + } else { + Licenses::select(&author) + }; create_dir(path)?; create_dir(path.join("addons"))?; diff --git a/bin/src/lib.rs b/bin/src/lib.rs index 9224ca8c..03aede7f 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -52,6 +52,7 @@ pub fn cli() -> Command { global = global .arg( clap::Arg::new("in-test") + .hide(true) .global(true) .help("we are in a test") .action(ArgAction::SetTrue) @@ -142,7 +143,9 @@ pub fn execute(matches: &ArgMatches) -> Result<(), Error> { }; if let Some(report) = report? { report.write_to_stdout(); - report.write_ci_annotations()?; + if !matches.subcommand_name().is_some_and(|s| s == "new") { + report.write_ci_annotations()?; + } if report.failed() { std::process::exit(1); } diff --git a/bin/tests/build.rs b/bin/tests/build.rs index 17c0a6b8..a6e81587 100644 --- a/bin/tests/build.rs +++ b/bin/tests/build.rs @@ -1,16 +1,19 @@ #![allow(clippy::unwrap_used)] +use sealed_test::prelude::*; + use hemtt::cli; -#[test] -/// # Panics -/// Will panic if there is an issue with the test -pub fn build() { - std::env::set_current_dir("tests/alpha").unwrap(); +#[sealed_test] +fn build_alpha() { + std::env::set_current_dir(format!("{}/tests/alpha", env!("CARGO_MANIFEST_DIR"))).unwrap(); hemtt::execute(&cli().get_matches_from(vec!["hemtt", "dev", "--in-test"])).unwrap(); hemtt::execute(&cli().get_matches_from(vec!["hemtt", "build", "--in-test"])).unwrap(); +} - std::env::set_current_dir("../bravo").unwrap(); +#[sealed_test] +fn build_bravo() { + std::env::set_current_dir(format!("{}/tests/bravo", env!("CARGO_MANIFEST_DIR"))).unwrap(); hemtt::execute(&cli().get_matches_from(vec!["hemtt", "script", "test"])).unwrap(); hemtt::execute(&cli().get_matches_from(vec!["hemtt", "release", "--in-test"])).unwrap(); } diff --git a/bin/tests/new.rs b/bin/tests/new.rs new file mode 100644 index 00000000..f4813e52 --- /dev/null +++ b/bin/tests/new.rs @@ -0,0 +1,10 @@ +#![allow(clippy::unwrap_used)] + +use hemtt::cli; + +use sealed_test::prelude::*; + +#[sealed_test] +fn new() { + hemtt::execute(&cli().get_matches_from(vec!["hemtt", "new", "test", "--in-test"])).unwrap(); +}