use super::*;
#[test]
fn adopt_without_a_dir_is_usage_rather_than_this_repo() {
assert_eq!(run_args(vec!["adopt".into()]), ExitCode::from(2));
assert_eq!(
run_args(vec!["adopt".into(), "--check".into()]),
ExitCode::from(2),
"a flag is not a dir"
);
}
fn adopt_fixture() -> Result<crate::testrepo::TestRepo, String> {
let r = crate::testrepo::TestRepo::new("cli-adopt")?;
r.write(
"SPEC.md",
"# SPEC\n\n## \u{a7}G GOAL\n\nx\n\n## \u{a7}F FEDERATION\n\n\
dir|owns|\u{22a5}owns|tokens\nsrc|parser input|the goal|-\n\n\
## \u{a7}V INVARIANTS\n\nV1: the parser rejects bad input\n",
)?;
r.write("src/SPEC.md", &spec::scaffold("src", &[]))?;
Ok(r)
}
#[test]
fn adopt_proposes_then_reruns_clean() -> Result<(), String> {
let r = adopt_fixture()?;
let dir = r.path().display().to_string();
let args = vec!["adopt".to_string(), dir];
assert_eq!(run_args(args.clone()), ExitCode::from(1), "V1 can move");
let map = r.path().join("map");
std::fs::write(&map, "V1 src\n").map_err(|e| e.to_string())?;
let mut with = args.clone();
with.extend(["--map".to_string(), map.display().to_string()]);
assert_eq!(run_args(with), ExitCode::from(1), "it wrote");
assert_eq!(run_args(args), ExitCode::SUCCESS, "nothing left to move");
Ok(())
}
#[test]
fn a_source_this_reader_cannot_parse_is_usage_not_nothing_to_move()
-> Result<(), String> {
let r = adopt_fixture()?;
r.write(
"SPEC.md",
"# SPEC\n\n## \u{a7}G GOAL\n\nx\n\n## \u{a7}F FEDERATION\n\n\
dir|owns|\u{22a5}owns|tokens\nsrc|parser input|the goal|-\n\n\
## \u{a7}T TASKS\n\n| id | status | task | cites |\n\
| --- | --- | --- | --- |\n| T1 | . | first task | - |\n",
)?;
let args = vec!["adopt".to_string(), r.path().display().to_string()];
assert_eq!(run_args(args.clone()), ExitCode::from(2));
let map = r.path().join("map");
std::fs::write(&map, "T1 src\n").map_err(|e| e.to_string())?;
let mut with = args;
with.extend(["--map".to_string(), map.display().to_string()]);
assert_eq!(run_args(with), ExitCode::from(2));
Ok(())
}