use clap::Parser;
use midenup::commands::Midenup;
mod common;
use common::*;
#[test]
fn integration_miden_test() {
let test_name = "integration_miden_test";
let test_env = environment_setup(test_name);
const FILE: &str =
full_path_manifest!("tests/data/integration_miden_test/channel-manifest.json");
let (mut local_manifest, config) = test_setup(&test_env, FILE);
let toolchain_dir = test_env.midenup_home.join("toolchains");
let command = Midenup::try_parse_from(["miden", "client", "--version"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to get client version");
assert!(test_env.midenup_home.exists());
assert!(toolchain_dir.exists());
assert!(test_env.cargo_home.join("bin").join("miden").exists());
let latest_toolchain = toolchain_dir.join("0.16.0");
assert!(latest_toolchain.exists());
let stable_dir = toolchain_dir.join("stable");
assert!(stable_dir.exists());
assert!(stable_dir.is_symlink());
let command = Midenup::try_parse_from(["midenup", "override", "0.15.0"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to override toolchain");
let command = Midenup::try_parse_from(["miden", "client", "--version"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to get client version");
let older_toolchain = toolchain_dir.join("0.15.0");
assert!(older_toolchain.exists());
let command = Midenup::try_parse_from(["midenup", "set", "0.14.0"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to set local toolchain");
let command = Midenup::try_parse_from(["miden", "client", "--version"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to get client version");
let oldest_toolchain = toolchain_dir.join("0.14.0");
assert!(oldest_toolchain.exists());
let installed_toolchains = ["0.14.0", "0.15.0", "0.16.0"].iter().map(|version| {
semver::Version::parse(version)
.unwrap_or_else(|_| panic!("Failed to turn {version} into semver::Version"))
});
local_manifest
.get_channels()
.map(|channel| channel.name.clone())
.eq(installed_toolchains);
}
#[test]
fn integration_miden_toolchain_toml() {
let test_name = "integration_miden_toolchain_toml";
let test_env = environment_setup(test_name);
let pwd = &test_env.present_working_dir;
const FILE: &str =
full_path_manifest!("tests/data/integration_miden_toolchain_toml/channel-manifest.json");
let (mut local_manifest, config) = test_setup(&test_env, FILE);
let command = Midenup::try_parse_from(["midenup", "set", "0.16.0"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to set local toolchain");
let miden_toolchain_file = pwd.join("miden-toolchain.toml");
assert!(miden_toolchain_file.exists());
let toolchain_with_components =
full_path!("tests/data/integration_miden_toolchain_toml/miden-toolchain-1.toml");
std::fs::copy(toolchain_with_components, &miden_toolchain_file).unwrap();
let command = Midenup::try_parse_from(["miden", "help", "toolchain"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to get subcommand help");
let toolchain_dir = test_env.midenup_home.join("toolchains");
assert!(toolchain_dir.exists());
let installed_channel =
local_manifest.get_channel_by_name(&semver::Version::new(0, 16, 0)).unwrap();
assert!(installed_channel.components.len() == 1);
let toolchain_with_components =
full_path!("tests/data/integration_miden_toolchain_toml/miden-toolchain-2.toml");
std::fs::copy(toolchain_with_components, miden_toolchain_file).unwrap();
let command = Midenup::try_parse_from(["miden", "help", "toolchain"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to get subcommand help");
let installed_channel = local_manifest
.get_channel_by_name(&semver::Version::new(0, 16, 0))
.unwrap()
.clone();
assert_eq!(installed_channel.components.len(), 4);
let command = Midenup::try_parse_from(["midenup", "update", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to update stable toolchain");
assert_eq!(installed_channel.components.len(), 4);
let command = Midenup::try_parse_from(["midenup", "install", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install stable toolchain");
let installed_channel =
local_manifest.get_channel_by_name(&semver::Version::new(0, 16, 0)).unwrap();
assert_eq!(installed_channel.components.len(), 6);
}
#[test]
#[should_panic]
fn integration_midenup_catches_installation_failure() {
let test_name = "midenup_catches_installation_failure";
let test_env = environment_setup(test_name);
const FILE_PRE_UPDATE: &str = full_path_manifest!(
"tests/data/unit_test_manifest_additional/manifest-uncompilable-midenc.json"
);
let (mut local_manifest, config) = test_setup(&test_env, FILE_PRE_UPDATE);
let command = Midenup::try_parse_from(["midenup", "install", "stable"]).unwrap();
command
.execute_with_manifest(&config, &mut local_manifest)
.expect("failed to install stable");
let manifest = test_env.midenup_home.join("manifest").with_extension("json");
assert!(manifest.exists());
}