Skip to content

Commit

Permalink
Add assert_cmd and predicated to dev deps (#2)
Browse files Browse the repository at this point in the history
* Add assert_cmd and predicated to dev deps

* Add e2e testing
  • Loading branch information
dottorblaster authored Oct 4, 2023
1 parent 5fcbf62 commit 487d7ad
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 7 deletions.
173 changes: 171 additions & 2 deletions Cargo.lock

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

8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ name = "fakemall"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.1.4", features = ["derive"] }
toml_edit = "0.19.0"
toml = "0.7.0"
serde = { version = "1.0.152", features = ["derive"] }
anyhow = "1.0.68"
anyhow = "1.0.68"

[dev-dependencies]
assert_cmd = "2.0.12"
predicates = "3.0.4"
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
fs::{self, File},
io::{Read, Write},
os::unix::prelude::PermissionsExt,
path::{PathBuf},
path::PathBuf,
process,
};
/// A simple tool for building fake command line interfaces
Expand Down Expand Up @@ -49,7 +49,7 @@ fn main() -> Result<()> {

match &cli.command {
Commands::Exec { set, command } => exec(set, command.trim()),
Commands::Save {.. } => todo!(),
Commands::Save { .. } => todo!(),
Commands::Build { set, path } => build(set, path),
}
}
Expand Down
41 changes: 41 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;

#[test]
fn fakes_commands() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("fakemall")?;

cmd.arg("exec")
.arg("tests/test_config.toml")
.arg("dmidecode");
cmd.assert()
.success()
.stdout(predicate::str::contains("this is a sample output"));

Ok(())
}

#[test]
fn set_doesnt_exist() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("fakemall")?;

cmd.arg("exec").arg("test/file/doesnt/exist").arg("kekw");
cmd.assert()
.failure()
.stderr(predicate::str::contains("No such file or directory"));

Ok(())
}

#[test]
fn command_doesnt_exist() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("fakemall")?;

cmd.arg("exec").arg("tests/test_config.toml").arg("asdf");
cmd.assert()
.failure()
.stdout(predicate::str::contains("asdf: command not found"));

Ok(())
}
3 changes: 3 additions & 0 deletions tests/test_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[commands]]
matches = "dmidecode"
output = "this is a sample output"

0 comments on commit 487d7ad

Please sign in to comment.