forked from mirrors/jj
tests: check set of files passed to diff-editor in jj edit
This commit is contained in:
parent
3907677c51
commit
066f74a1b4
2 changed files with 44 additions and 1 deletions
|
@ -12,6 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
use std::process::exit;
|
||||
|
||||
|
@ -29,6 +30,22 @@ struct Args {
|
|||
after: PathBuf,
|
||||
}
|
||||
|
||||
fn files_recursively(dir: &PathBuf) -> HashSet<String> {
|
||||
let mut files = HashSet::new();
|
||||
for dir_entry in std::fs::read_dir(dir).unwrap() {
|
||||
let dir_entry = dir_entry.unwrap();
|
||||
let base_name = dir_entry.file_name().to_str().unwrap().to_string();
|
||||
if dir_entry.path().is_dir() {
|
||||
for sub_path in files_recursively(&dir_entry.path()) {
|
||||
files.insert(format!("{base_name}/{sub_path}"));
|
||||
}
|
||||
} else {
|
||||
files.insert(base_name);
|
||||
}
|
||||
}
|
||||
files
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Args = Args::parse();
|
||||
let edit_script_path = PathBuf::from(std::env::var_os("EDIT_SCRIPT").unwrap());
|
||||
|
@ -39,6 +56,28 @@ fn main() {
|
|||
match parts.as_slice() {
|
||||
[""] => {}
|
||||
["fail"] => exit(1),
|
||||
["files-before", ..] => {
|
||||
let expected = parts[1..].iter().copied().map(str::to_string).collect();
|
||||
let actual = files_recursively(&args.before);
|
||||
if actual != expected {
|
||||
eprintln!(
|
||||
"unexpected files before: {:?}",
|
||||
actual.iter().sorted().collect_vec()
|
||||
);
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
["files-after", ..] => {
|
||||
let expected = parts[1..].iter().copied().map(str::to_string).collect();
|
||||
let actual = files_recursively(&args.after);
|
||||
if actual != expected {
|
||||
eprintln!(
|
||||
"unexpected files after: {:?}",
|
||||
actual.iter().sorted().collect_vec()
|
||||
);
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
["rm", file] => {
|
||||
std::fs::remove_file(args.after.join(file)).unwrap();
|
||||
}
|
||||
|
|
|
@ -32,7 +32,11 @@ fn test_edit() {
|
|||
let edit_script = test_env.set_up_fake_diff_editor();
|
||||
|
||||
// Nothing happens if we make no changes
|
||||
std::fs::write(&edit_script, "").unwrap();
|
||||
std::fs::write(
|
||||
&edit_script,
|
||||
"files-before file1 file2\0files-after JJ-INSTRUCTIONS file2",
|
||||
)
|
||||
.unwrap();
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["edit"]);
|
||||
insta::assert_snapshot!(stdout, @"Nothing changed.
|
||||
");
|
||||
|
|
Loading…
Reference in a new issue