mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-19 19:08:08 +00:00
fake-editor: replace expectpath with dump-path
This allows us to assert the expected path in the test itself, rather than in the fake editor.
This commit is contained in:
parent
1eef1a4f55
commit
3bca159b1a
2 changed files with 17 additions and 21 deletions
|
@ -50,6 +50,11 @@ fn main() {
|
|||
let dest_path = edit_script_path.parent().unwrap().join(dest);
|
||||
fs::copy(&args.file, dest_path).unwrap();
|
||||
}
|
||||
["dump-path", dest] => {
|
||||
let dest_path = edit_script_path.parent().unwrap().join(dest);
|
||||
fs::write(&dest_path, args.file.to_str().unwrap())
|
||||
.unwrap_or_else(|err| panic!("Failed to write file {dest_path:?}: {err}"));
|
||||
}
|
||||
["expect"] => {
|
||||
let actual = String::from_utf8(fs::read(&args.file).unwrap()).unwrap();
|
||||
if actual != payload {
|
||||
|
@ -58,14 +63,6 @@ fn main() {
|
|||
exit(1)
|
||||
}
|
||||
}
|
||||
["expectpath"] => {
|
||||
let actual = args.file.to_str().unwrap();
|
||||
if actual != payload {
|
||||
eprintln!("fake-editor: Unexpected path.\n");
|
||||
eprintln!("EXPECTED: <{payload}>\nRECEIVED: <{actual}>");
|
||||
exit(1)
|
||||
}
|
||||
}
|
||||
["write"] => {
|
||||
fs::write(&args.file, payload).unwrap_or_else(|_| {
|
||||
panic!("Failed to write file {}", args.file.to_str().unwrap())
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use insta::assert_snapshot;
|
||||
use itertools::Itertools;
|
||||
use regex::Regex;
|
||||
|
@ -621,12 +623,12 @@ 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, "dump-path path").unwrap();
|
||||
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--user"]);
|
||||
|
||||
let edited_path =
|
||||
PathBuf::from(std::fs::read_to_string(test_env.env_root().join("path")).unwrap());
|
||||
assert_eq!(&edited_path, test_env.config_path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -636,15 +638,12 @@ 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, "dump-path path").unwrap();
|
||||
test_env.jj_cmd_ok(&repo_path, &["config", "edit", "--repo"]);
|
||||
|
||||
let edited_path =
|
||||
PathBuf::from(std::fs::read_to_string(test_env.env_root().join("path")).unwrap());
|
||||
assert_eq!(edited_path, repo_path.join(".jj/repo/config.toml"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue