mirror of
https://github.com/Noratrieb/fix-und-fertig.git
synced 2026-01-16 03:35:02 +01:00
STUFF
This commit is contained in:
parent
fb5208f734
commit
d964157bfc
14 changed files with 900 additions and 1 deletions
21
tests/helpers.rs
Normal file
21
tests/helpers.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
use clap::{CommandFactory, FromArgMatches};
|
||||
use color_eyre::Result;
|
||||
use std::ffi::OsStr;
|
||||
|
||||
use fix_und_fertig::cli::Cli;
|
||||
|
||||
pub fn tmpdir() -> tempfile::TempDir {
|
||||
tempfile::TempDir::new().unwrap()
|
||||
}
|
||||
|
||||
pub fn run_in<S: AsRef<OsStr>>(dir: &tempfile::TempDir, args: impl AsRef<[S]>) -> Result<()> {
|
||||
let mut matches = <Cli as CommandFactory>::command().get_matches_from(
|
||||
[OsStr::new("fuf")]
|
||||
.into_iter()
|
||||
.chain(args.as_ref().into_iter().map(AsRef::as_ref)),
|
||||
);
|
||||
let cli =
|
||||
<Cli as FromArgMatches>::from_arg_matches_mut(&mut matches).expect("invalid CLI args");
|
||||
|
||||
fix_und_fertig::cli::run_command(dir.path(), cli)
|
||||
}
|
||||
27
tests/init.rs
Normal file
27
tests/init.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
mod helpers;
|
||||
use helpers::*;
|
||||
|
||||
#[test]
|
||||
fn init() {
|
||||
let dir = tmpdir();
|
||||
|
||||
run_in(&dir, ["init"]).unwrap();
|
||||
|
||||
assert!(dir.path().join(".fuf").is_dir());
|
||||
assert!(dir.path().join(".fuf").join("db").is_dir());
|
||||
assert!(dir.path().join(".fuf").join("db").join("objects").is_dir());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn double_init() {
|
||||
let dir = tmpdir();
|
||||
|
||||
run_in(&dir, ["init"]).unwrap();
|
||||
|
||||
assert!(dir.path().join(".fuf").is_dir());
|
||||
assert!(dir.path().join(".fuf").join("db").is_dir());
|
||||
assert!(dir.path().join(".fuf").join("db").join("objects").is_dir());
|
||||
|
||||
|
||||
assert!(run_in(&dir, ["init"]).is_err());
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue