Skip to content

Commit

Permalink
fake-editor: add dumppath command
Browse files Browse the repository at this point in the history
This allows us to assert the expected path in the test itself, rather
than in the fake editor.
  • Loading branch information
mlcui-corp committed Jun 30, 2024
1 parent 3792f4a commit 9267cc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
6 changes: 6 additions & 0 deletions cli/testing/fake-editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ fn main() {
let dest_path = edit_script_path.parent().unwrap().join(dest);
fs::copy(&args.file, dest_path).unwrap();
}
["dumppath", dest] => {
let dest_path = edit_script_path.parent().unwrap().join(dest);
fs::write(&dest_path, args.file.to_str().unwrap()).unwrap_or_else(|_| {
panic!("Failed to write file {}", args.file.to_str().unwrap())
});
}
["expect"] => {
let actual = String::from_utf8(fs::read(&args.file).unwrap()).unwrap();
if actual != payload {
Expand Down
25 changes: 12 additions & 13 deletions cli/tests/test_config_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,13 @@ fn test_config_edit_user() {
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();

std::fs::write(
edit_script,
format!("expectpath\n{}", test_env.config_path().to_str().unwrap()),
)
.unwrap();
std::fs::write(edit_script, ["dumppath path"].join("\0")).unwrap();
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--user"]);

assert_eq!(
std::fs::read_to_string(test_env.env_root().join("path")).unwrap(),
test_env.config_path().to_str().unwrap()
);
}

#[test]
Expand All @@ -636,15 +637,13 @@ fn test_config_edit_repo() {
let repo_path = test_env.env_root().join("repo");
let edit_script = test_env.set_up_fake_editor();

std::fs::write(
edit_script,
format!(
"expectpath\n{}",
repo_path.join(".jj/repo/config.toml").to_str().unwrap()
),
)
.unwrap();
std::fs::write(edit_script, ["dumppath path"].join("\0")).unwrap();
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--repo"]);

assert_eq!(
std::fs::read_to_string(test_env.env_root().join("path")).unwrap(),
repo_path.join(".jj/repo/config.toml").to_str().unwrap()
);
}

#[test]
Expand Down

0 comments on commit 9267cc7

Please sign in to comment.