use assert_cmd::cargo::cargo_bin_cmd;
use assert_fs::prelude::*;
use predicates::prelude::*;
use std::path::Path;

#[test]
fn command_initial_setup() {
    let depot_dir = assert_fs::TempDir::new().unwrap();

    depot_dir
        .child(Path::new("juliaup"))
        .assert(predicate::path::missing());

    cargo_bin_cmd!("juliaup")
        .arg("46029ef5-0b73-4a71-bff3-d0d05de42aac")
        .env("JULIA_DEPOT_PATH", depot_dir.path())
        .env("JULIAUP_DEPOT_PATH", depot_dir.path())
        .assert()
        .success()
        .stdout(predicate::str::is_empty())
        .stderr(
            predicate::str::starts_with(
                "    Checking for new Julia versions\n  Installing Julia 1.",
            )
            .and(
                predicate::str::contains("apple.darwin14")
                    .not()
                    .or(
                        predicate::str::contains("Checking standard library notarization")
                            .and(predicate::str::contains("done.\n"))
                            .or(predicate::str::contains("Mounting installer")),
                    ),
            ),
        );

    depot_dir
        .child(Path::new("juliaup").join("juliaup.json"))
        .assert(predicate::path::exists());
}
