scarb-metadata 1.15.1

Structured access to the output of `scarb metadata`
Documentation
use assert_fs::TempDir;
use snapbox::cmd::{Command, cargo_bin};
use std::env;
use std::path::PathBuf;

use scarb_metadata::MetadataCommand;

fn scarb_bin() -> PathBuf {
    env::var_os("SCARB_TEST_BIN")
        .map(PathBuf::from)
        .unwrap_or_else(|| cargo_bin("scarb"))
}

#[test]
fn empty_project() {
    let t = TempDir::new().unwrap();

    let result = MetadataCommand::new()
        .scarb_path(scarb_bin())
        .current_dir(t.path())
        .inherit_stderr()
        .exec();

    assert!(
        result
            .unwrap_err()
            .to_string()
            .contains("failed to read manifest")
    );
}

#[test]
fn sample_project() {
    let t = TempDir::new().unwrap();
    init_project(&t);

    MetadataCommand::new()
        .scarb_path(scarb_bin())
        .current_dir(t.path())
        .inherit_stderr()
        .exec()
        .unwrap();
}

#[test]
fn no_deps() {
    let t = TempDir::new().unwrap();
    init_project(&t);

    MetadataCommand::new()
        .scarb_path(scarb_bin())
        .no_deps()
        .current_dir(t.path())
        .inherit_stderr()
        .exec()
        .unwrap();
}

#[test]
fn manifest_path() {
    let t = TempDir::new().unwrap();
    init_project(&t);

    MetadataCommand::new()
        .scarb_path(scarb_bin())
        .manifest_path(t.join("Scarb.toml").as_path())
        .inherit_stderr()
        .exec()
        .unwrap();
}

fn init_project(t: &TempDir) {
    Command::new(scarb_bin())
        .args(["init", "--name", "hello"])
        .env("SCARB_INIT_TEST_RUNNER", "cairo-test")
        .current_dir(t)
        .assert()
        .success();
}