From b89b8ef7f2920804675470cc001de44a9ec02986 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Mon, 2 Dec 2024 10:57:57 -0800 Subject: [PATCH] Add tests. --- crates/cli/src/error.rs | 2 +- crates/cli/src/helpers.rs | 2 +- crates/cli/tests/install_all_test.rs | 43 ++++++++++++++++++++++ crates/cli/tests/install_uninstall_test.rs | 38 +++++++++++++++++-- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/crates/cli/src/error.rs b/crates/cli/src/error.rs index 8bc4a0571..fab4555fc 100644 --- a/crates/cli/src/error.rs +++ b/crates/cli/src/error.rs @@ -44,7 +44,7 @@ pub enum ProtoCliError { #[diagnostic( code(proto::cli::requirements_not_met), - help("Try adding the required tool to .prototools") + help("Try configuring a version of the required tool in .prototools") )] #[error( "{} requires {} to function correctly, but it has not been installed.", diff --git a/crates/cli/src/helpers.rs b/crates/cli/src/helpers.rs index dac086c9c..d3db42c12 100644 --- a/crates/cli/src/helpers.rs +++ b/crates/cli/src/helpers.rs @@ -164,7 +164,7 @@ pub fn create_progress_spinner>(start: S) -> ProgressBar { // When not a TTY, we should display something to the user! pub fn print_progress_state(pb: &ProgressBar, message: String) { - if message.is_empty() { + if message.is_empty() || pb.message() == message { return; } diff --git a/crates/cli/tests/install_all_test.rs b/crates/cli/tests/install_all_test.rs index a39da52aa..fb6806249 100644 --- a/crates/cli/tests/install_all_test.rs +++ b/crates/cli/tests/install_all_test.rs @@ -1,5 +1,6 @@ mod utils; +use starbase_sandbox::predicates::prelude::*; use utils::*; mod install_all { @@ -98,4 +99,46 @@ deno = "1.30.0" assert!(node_path.exists()); assert!(deno_path.exists()); } + + mod reqs { + use super::*; + + #[test] + fn errors_if_reqs_not_met() { + let sandbox = create_empty_proto_sandbox(); + sandbox.create_file(".prototools", r#"npm = "9.0.0""#); + + let assert = sandbox + .run_bin(|cmd| { + cmd.arg("install"); + }) + .failure(); + + assert.stderr(predicate::str::contains( + "npm requires node to function correctly", + )); + } + + #[test] + fn passes_if_reqs_met() { + let sandbox = create_empty_proto_sandbox(); + sandbox.create_file( + ".prototools", + r#"node = "19.0.0" +npm = "10.0.0" + "#, + ); + + let assert = sandbox + .run_bin(|cmd| { + cmd.arg("install"); + }) + .success(); + + assert.stdout( + predicate::str::contains("Waiting on requirements: node") + .and(predicate::str::contains("npm 10.0.0 installed!")), + ); + } + } } diff --git a/crates/cli/tests/install_uninstall_test.rs b/crates/cli/tests/install_uninstall_test.rs index daf8ef0e3..114336edd 100644 --- a/crates/cli/tests/install_uninstall_test.rs +++ b/crates/cli/tests/install_uninstall_test.rs @@ -3,11 +3,10 @@ mod utils; use proto_core::{Id, PinType, ProtoConfig, ToolManifest, UnresolvedVersionSpec, VersionSpec}; use rustc_hash::FxHashSet; use starbase_sandbox::predicates::prelude::*; +use std::{fs, time::SystemTime}; use utils::*; mod install_uninstall { - use std::{fs, time::SystemTime}; - use super::*; #[test] @@ -86,7 +85,6 @@ mod install_uninstall { )); // Uninstall - let assert = sandbox .run_bin(|cmd| { cmd.arg("uninstall").arg("node").arg("19.0.0"); @@ -246,7 +244,6 @@ mod install_uninstall { let manifest_file = sandbox.path().join(".proto/tools/node/manifest.json"); // Install - sandbox .run_bin(|cmd| { cmd.arg("install") @@ -654,4 +651,37 @@ mod install_uninstall { assert!(link3.exists()); } } + + mod reqs { + use super::*; + + #[test] + fn errors_if_reqs_not_met() { + let sandbox = create_empty_proto_sandbox(); + + let assert = sandbox + .run_bin(|cmd| { + cmd.arg("install").arg("npm").arg("10.0.0"); + }) + .failure(); + + assert.stderr(predicate::str::contains( + "npm requires node to function correctly", + )); + } + + #[test] + fn passes_if_reqs_met() { + let sandbox = create_empty_proto_sandbox(); + sandbox.create_file(".prototools", r#"node = "20""#); + + let assert = sandbox + .run_bin(|cmd| { + cmd.arg("install").arg("npm").arg("10.0.0"); + }) + .success(); + + assert.stdout(predicate::str::contains("npm 10.0.0 has been installed")); + } + } }