Skip to content

Commit

Permalink
try a basic runtest
Browse files Browse the repository at this point in the history
  • Loading branch information
mistydemeo committed Apr 3, 2024
1 parent 16a43c8 commit 2409318
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cargo-dist/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ tokio = { version = "1.36.0", features = ["full"] }
temp-dir = "0.1.13"

[dev-dependencies]
homedir = "0.2.1"
insta = { version = "1.38.0", features = ["filters"] }
tar = "0.4.38"
flate2 = "1.0.24"
Expand Down
62 changes: 62 additions & 0 deletions cargo-dist/tests/cli-tests.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::process::{Command, Output, Stdio};

static BIN: &str = env!("CARGO_BIN_EXE_cargo-dist");
const ENV_RUIN_ME: &str = "RUIN_MY_COMPUTER_WITH_INSTALLERS";

#[allow(dead_code)]
mod gallery;
use axoasset::LocalAsset;
use camino::Utf8PathBuf;
use gallery::*;

fn format_outputs(output: &Output) -> String {
Expand Down Expand Up @@ -191,3 +194,62 @@ fn test_markdown_help() {
});
assert!(output.status.success(), "{}", output.status);
}

static RECEIPT_TEMPLATE: &str = r#"{"binaries":["cargo-dist"],"install_prefix":"INSTALL_PREFIX","provider":{"source":"cargo-dist","version":"0.10.0-prerelease.1"},"source":{"app_name":"cargo-dist","name":"cargo-dist","owner":"axodotdev","release_type":"github"},"version":"VERSION"}"#;

fn install_receipt(version: &str, prefix: &Utf8PathBuf) -> String {
RECEIPT_TEMPLATE
.replace("INSTALL_PREFIX", &prefix.to_string().replace('\\', "\\\\"))
.replace("VERSION", version)
}

fn write_receipt(version: &str, prefix: &Utf8PathBuf, config_path: &Utf8PathBuf) {
let contents = install_receipt(version, prefix);
let receipt_name = config_path.join("cargo-dist-receipt.json");
LocalAsset::write_new(&contents, receipt_name).unwrap();
}

#[test]
fn test_self_update() {
// Only do this if RUIN_MY_COMPUTER_WITH_INSTALLERS is set
// Also keep it to Mac/Linux until I remember how Windows paths work
#[cfg(target_family = "unix")]
if std::env::var(ENV_RUIN_ME)
.map(|s| !s.is_empty())
.unwrap_or(false)
{
let dist_home = Utf8PathBuf::from_path_buf(
homedir::get_my_home()
.unwrap()
.unwrap()
.join(".cargo")
.join("bin"),
)
.unwrap();
let dist_path = &dist_home.join("cargo-dist");
let config_path = Utf8PathBuf::from_path_buf(
homedir::get_my_home()
.unwrap()
.unwrap()
.join(".config")
.join("cargo-dist"),
)
.unwrap();

// Install to the home directory
std::fs::copy(BIN, dist_path).unwrap();

// Create a fake install receipt
write_receipt("0.13.0", &dist_home, &config_path);

let output = Command::new(dist_path)
.arg("dist")
.arg("update")
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.output()
.unwrap();

assert!(output.status.success());
}
}

0 comments on commit 2409318

Please sign in to comment.