use assert_cmd::prelude::*;
use assert_fs::prelude::*;
use predicates::prelude::*;
use serial_test::serial;
use std::process::Command;
mod util;
#[test]
#[serial]
fn bury_moves_file_to_graveyard_and_updates_index() -> Result<(), Box<dyn std::error::Error>> {
let tmp = assert_fs::TempDir::new()?;
let file = tmp.child("hello.txt");
file.write_str("hi")?;
let data = tmp.child(".local/share");
util::set_var("XDG_DATA_HOME", data.path());
Command::cargo_bin("nrip")? .arg(file.path())
.assert()
.success()
.stderr(predicate::str::is_empty());
file.assert(predicate::path::missing());
let gy = data.child("nrip/graveyard");
gy.assert(predicate::path::exists());
let index = data.child("nrip/index.json");
let idx_str = std::fs::read_to_string(index.path())?;
assert!(idx_str.contains("hello.txt"));
tmp.close()?;
Ok(())
}