Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fake-editor: replace expectpath with dump-path #3995

Merged
merged 1 commit into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions cli/testing/fake-editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
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 @@ -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;
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand Down