Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 112 additions & 1 deletion Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ encoding_rs = ">=0.8.0, <=0.8.29"

[dev-dependencies]
toml = "0.5"

assert_cmd = "2"
predicates = "2.1"
tempdir = "0.3"
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ pub fn cli() -> Command {

.arg(Arg::new("env")
.required(false)
.num_args(0)
.num_args(1)
.short('E')
.long("env")
.value_parser(ValueParser::new(env_pass_validator))
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
unused,
unused_allocation,
unused_comparisons,
unused_crate_dependencies,
unused_extern_crates,
unused_import_braces,
unused_imports,
Expand Down
27 changes: 27 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use std::process::Command; // Run programs
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*; // Used for writing assertions

mod common;

#[test]
fn test_cli_build() -> Result<(), Box<dyn std::error::Error>> {
let tmpdir = tempdir::TempDir::new("butido")?;
common::setup_cwd(&tmpdir)?;
let mut cmd = Command::cargo_bin("butido")?;

cmd.current_dir(tmpdir.as_ref())
.arg("build")
.arg("example")
.arg("-I")
.arg("foo:bar")
.arg("example")
.arg("1.0.0");

// butido cannot do anything if there are no packages. So this should fail.
cmd.assert()
.failure()
.stderr(predicate::str::contains("No such file or directory"));

Ok(())
}
42 changes: 42 additions & 0 deletions tests/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use std::path::Path;
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*;

const CONFIG: &str = include_str!("../config.toml");

pub fn setup_cwd<P: AsRef<Path>>(path: P) -> Result<(), Box<dyn std::error::Error>> {
let mut toml: toml::Value = toml::from_str(CONFIG)?;

for (key, value) in [
("releases_root", "releases"),
("staging", "staging"),
("source_cache", "sources"),
("log_dir", "logs"),
] {
let path = path.as_ref().join(value);
std::fs::create_dir(&path)?;
let value = toml::Value::String(path.display().to_string());
let toml_key = toml
.get_mut(key)
.ok_or_else(|| format!("{} missing in configuration", key))?;
*toml_key = value
}

std::fs::write(
path.as_ref().join("config.toml"),
toml::to_string_pretty(&toml)?,
)?;

std::fs::write(
path.as_ref().join("pkg.toml"),
""
)?;

std::process::Command::new("git")
.current_dir(path)
.arg("init")
.assert()
.success();

Ok(())
}