use dors::DorsError;
use dors::{all_tasks, run};
#[test]
fn test_workspace_only() {
[
"check",
"should-be-on-member",
"should-run-before-only-once",
"should-run-after-only-once",
]
.iter()
.for_each(|task| assert!(run(task, "./tests/workspace_only").unwrap().success()));
}
#[test]
fn test_workspace_failures() {
["should-fail", "should-fail-in-multiline"]
.iter()
.for_each(|task| {
assert_eq!(
run(task, "./tests/workspace_only").unwrap().code().unwrap(),
55
)
});
}
#[test]
fn test_member_only() {
[
"should-be-here",
"should-be-here-explicit",
"should-be-in-workspace",
"should-be-in-tests",
"should-be-one",
"should-be-one-at-root",
"should-have-default-env",
]
.iter()
.for_each(|task| {
assert!(run(task, "./tests/workspace_member_only/member1")
.unwrap()
.success())
});
}
#[test]
fn test_workspace_all() {
println!("testing workspace all");
[
"should-not-overwrite",
"should-overwrite-members",
"nested-works-with-run-variants",
"only-member1",
"only-member2",
"should-inherit-envs",
]
.iter()
.for_each(|task| {
println!("starting test: {:?}", task);
let result = run(task, "./tests/workspace_all").unwrap().success();
println!("test result: {:?}", result);
assert!(result);
});
}
#[test]
fn test_workspace_all_failures() {
["should-overwrite"].iter().for_each(|task| {
assert_eq!(
run(task, "./tests/workspace_all").unwrap().code().unwrap(),
55
)
});
["should-overwrite"].iter().for_each(|task| {
assert_eq!(
run(task, "./tests/workspace_all/member2")
.unwrap()
.code()
.unwrap(),
55
)
});
}
#[test]
fn test_workspace_all_member1() {
["should-overwrite"].iter().for_each(|task| {
assert!(run(task, "./tests/workspace_all/member1")
.unwrap()
.success())
});
}
#[test]
fn test_list_workspace_all() {
let mut all_tasks = all_tasks("./tests/workspace_all").unwrap();
all_tasks.sort();
assert_eq!(
all_tasks,
[
"check",
"nested-works-with-run-variants",
"only-member1",
"only-member2",
"should-inherit-envs",
"should-not-overwrite",
"should-overwrite",
"should-overwrite-members"
]
);
}
#[test]
fn test_no_task() {
let err = run("fake-task", "tests/workspace_all").unwrap_err();
assert!(matches!(
err.kind(),
DorsError::NoTask(task_name) if task_name == "fake-task"
));
}
#[test]
fn test_no_dorsfiles() {
let tmp_file = "tests/no_dorsfiles/Dorsfile.toml";
assert!(matches!(
all_tasks("./tests/no_dorsfiles").unwrap_err().kind(),
DorsError::NoDorsfile
));
assert!(matches!(
run("", "tests/no_dorsfiles/member1").unwrap_err().kind(),
DorsError::NoMemberDorsfile
));
std::fs::write(tmp_file, b"invalid-syntax").unwrap();
assert!(matches!(
all_tasks("tests/no_dorsfiles").unwrap_err().kind(),
DorsError::CouldNotParseDorsfile(_)
));
std::fs::write(tmp_file, b"[task.a]\nunexpected-field=1").unwrap();
assert!(matches!(
all_tasks("tests/no_dorsfiles").unwrap_err().kind(),
DorsError::CouldNotParseDorsfile(_)
));
std::fs::remove_file(tmp_file).unwrap();
}