Skip to content

Commit

Permalink
Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Dec 2, 2024
1 parent bc76aeb commit b89b8ef
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/cli/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ pub fn create_progress_spinner<S: AsRef<str>>(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;
}

Expand Down
43 changes: 43 additions & 0 deletions crates/cli/tests/install_all_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod utils;

use starbase_sandbox::predicates::prelude::*;
use utils::*;

mod install_all {
Expand Down Expand Up @@ -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!")),
);
}
}
}
38 changes: 34 additions & 4 deletions crates/cli/tests/install_uninstall_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -86,7 +85,6 @@ mod install_uninstall {
));

// Uninstall

let assert = sandbox
.run_bin(|cmd| {
cmd.arg("uninstall").arg("node").arg("19.0.0");
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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"));
}
}
}

0 comments on commit b89b8ef

Please sign in to comment.