mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-28 10:31:14 +00:00
tests: compare CommandOutput where makes sense
This commit is contained in:
parent
c9926eae4c
commit
b7e2932dba
@ -33,11 +33,7 @@ fn test_track_untrack() {
|
||||
// patterns
|
||||
test_env.jj_cmd_ok(&repo_path, &["st"]);
|
||||
std::fs::write(repo_path.join(".gitignore"), "*.bak\n").unwrap();
|
||||
let files_before = test_env
|
||||
.run_jj_in(&repo_path, ["file", "list"])
|
||||
.success()
|
||||
.stdout
|
||||
.into_raw();
|
||||
let files_before = test_env.run_jj_in(&repo_path, ["file", "list"]).success();
|
||||
|
||||
// Errors out when not run at the head operation
|
||||
let output = test_env.run_jj_in(&repo_path, ["file", "untrack", "file1", "--at-op", "@-"]);
|
||||
@ -71,16 +67,12 @@ fn test_track_untrack() {
|
||||
[EOF]
|
||||
[exit status: 1]
|
||||
");
|
||||
let files_after = test_env
|
||||
.run_jj_in(&repo_path, ["file", "list"])
|
||||
.success()
|
||||
.stdout
|
||||
.into_raw();
|
||||
let files_after = test_env.run_jj_in(&repo_path, ["file", "list"]).success();
|
||||
// There should be no changes to the state when there was an error
|
||||
assert_eq!(files_after, files_before);
|
||||
|
||||
// Can untrack a single file
|
||||
assert!(files_before.contains("file1.bak\n"));
|
||||
assert!(files_before.stdout.raw().contains("file1.bak\n"));
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["untrack", "file1.bak"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @r"
|
||||
@ -88,15 +80,11 @@ fn test_track_untrack() {
|
||||
Warning: `jj untrack` will be removed in a future version, and this will be a hard error
|
||||
[EOF]
|
||||
");
|
||||
let files_after = test_env
|
||||
.run_jj_in(&repo_path, ["file", "list"])
|
||||
.success()
|
||||
.stdout
|
||||
.into_raw();
|
||||
let files_after = test_env.run_jj_in(&repo_path, ["file", "list"]).success();
|
||||
// The file is no longer tracked
|
||||
assert!(!files_after.contains("file1.bak"));
|
||||
assert!(!files_after.stdout.raw().contains("file1.bak"));
|
||||
// Other files that match the ignore pattern are not untracked
|
||||
assert!(files_after.contains("file2.bak"));
|
||||
assert!(files_after.stdout.raw().contains("file2.bak"));
|
||||
// The files still exist on disk
|
||||
assert!(repo_path.join("file1.bak").exists());
|
||||
assert!(repo_path.join("file2.bak").exists());
|
||||
@ -117,12 +105,8 @@ fn test_track_untrack() {
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["file", "untrack", "target"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
let files_after = test_env
|
||||
.run_jj_in(&repo_path, ["file", "list"])
|
||||
.success()
|
||||
.stdout
|
||||
.into_raw();
|
||||
assert!(!files_after.contains("target"));
|
||||
let files_after = test_env.run_jj_in(&repo_path, ["file", "list"]).success();
|
||||
assert!(!files_after.stdout.raw().contains("target"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -101,27 +101,11 @@ fn test_no_subcommand() {
|
||||
let output = test_env
|
||||
.run_jj_in(test_env.env_root(), ["-R", "repo"])
|
||||
.success();
|
||||
assert_eq!(
|
||||
output.stdout.raw(),
|
||||
test_env
|
||||
.run_jj_in(&repo_path, ["log"])
|
||||
.success()
|
||||
.stdout
|
||||
.raw()
|
||||
);
|
||||
insta::assert_snapshot!(output.stderr, @"");
|
||||
assert_eq!(output, test_env.run_jj_in(&repo_path, ["log"]));
|
||||
|
||||
// Inside of a repo.
|
||||
let output = test_env.run_jj_in(&repo_path, [""; 0]).success();
|
||||
assert_eq!(
|
||||
output.stdout.raw(),
|
||||
test_env
|
||||
.run_jj_in(&repo_path, ["log"])
|
||||
.success()
|
||||
.stdout
|
||||
.raw()
|
||||
);
|
||||
insta::assert_snapshot!(output.stderr, @"");
|
||||
assert_eq!(output, test_env.run_jj_in(&repo_path, ["log"]));
|
||||
|
||||
// Command argument that looks like a command name.
|
||||
test_env
|
||||
@ -184,7 +168,7 @@ fn test_ignore_working_copy() {
|
||||
&repo_path,
|
||||
["log", "-T", "commit_id", "--ignore-working-copy"],
|
||||
);
|
||||
assert_eq!(output_again.stdout.raw(), output.stdout.raw());
|
||||
assert_eq!(output_again, output);
|
||||
|
||||
// But without --ignore-working-copy, we get a new commit ID.
|
||||
let output = test_env.run_jj_in(&repo_path, ["log", "-T", "commit_id"]);
|
||||
|
@ -20,28 +20,22 @@ fn test_help() {
|
||||
|
||||
let help_cmd = test_env.run_jj_in(test_env.env_root(), ["help"]).success();
|
||||
// The help command output should be equal to the long --help flag
|
||||
let help_flag = test_env
|
||||
.run_jj_in(test_env.env_root(), ["--help"])
|
||||
.success();
|
||||
assert_eq!(help_cmd.stdout.raw(), help_flag.stdout.raw());
|
||||
let help_flag = test_env.run_jj_in(test_env.env_root(), ["--help"]);
|
||||
assert_eq!(help_cmd, help_flag);
|
||||
|
||||
// Help command should work with commands
|
||||
let help_cmd = test_env
|
||||
.run_jj_in(test_env.env_root(), ["help", "log"])
|
||||
.success();
|
||||
let help_flag = test_env
|
||||
.run_jj_in(test_env.env_root(), ["log", "--help"])
|
||||
.success();
|
||||
assert_eq!(help_cmd.stdout.raw(), help_flag.stdout.raw());
|
||||
let help_flag = test_env.run_jj_in(test_env.env_root(), ["log", "--help"]);
|
||||
assert_eq!(help_cmd, help_flag);
|
||||
|
||||
// Help command should work with subcommands
|
||||
let help_cmd = test_env
|
||||
.run_jj_in(test_env.env_root(), ["help", "workspace", "root"])
|
||||
.success();
|
||||
let help_flag = test_env
|
||||
.run_jj_in(test_env.env_root(), ["workspace", "root", "--help"])
|
||||
.success();
|
||||
assert_eq!(help_cmd.stdout.raw(), help_flag.stdout.raw());
|
||||
let help_flag = test_env.run_jj_in(test_env.env_root(), ["workspace", "root", "--help"]);
|
||||
assert_eq!(help_cmd, help_flag);
|
||||
|
||||
// Help command should not work recursively
|
||||
let output = test_env.run_jj_in(test_env.env_root(), ["workspace", "help", "root"]);
|
||||
@ -76,17 +70,14 @@ fn test_help() {
|
||||
let help_cmd = test_env.run_jj_in(test_env.env_root(), ["help", "nonexistent"]);
|
||||
let help_flag = test_env.run_jj_in(test_env.env_root(), ["nonexistent", "--help"]);
|
||||
assert_eq!(help_cmd.status.code(), Some(2), "{help_cmd}");
|
||||
assert_eq!(help_flag.status.code(), Some(2), "{help_flag}");
|
||||
assert_eq!(help_cmd.stderr.raw(), help_flag.stderr.raw());
|
||||
assert_eq!(help_cmd, help_flag);
|
||||
|
||||
// Some edge cases
|
||||
let help_cmd = test_env
|
||||
.run_jj_in(test_env.env_root(), ["help", "help"])
|
||||
.success();
|
||||
let help_flag = test_env
|
||||
.run_jj_in(test_env.env_root(), ["help", "--help"])
|
||||
.success();
|
||||
assert_eq!(help_cmd.stdout.raw(), help_flag.stdout.raw());
|
||||
let help_flag = test_env.run_jj_in(test_env.env_root(), ["help", "--help"]);
|
||||
assert_eq!(help_cmd, help_flag);
|
||||
|
||||
let output = test_env.run_jj_in(test_env.env_root(), ["help", "unknown"]);
|
||||
insta::assert_snapshot!(output, @r"
|
||||
|
@ -1070,8 +1070,8 @@ fn test_op_diff() {
|
||||
- untracked pukowqtp 0cb7e07e bookmark-1 | Commit 1
|
||||
[EOF]
|
||||
");
|
||||
let output_without_from_to = test_env.run_jj_in(&repo_path, ["op", "diff"]).success();
|
||||
assert_eq!(output.stdout.raw(), output_without_from_to.stdout.raw());
|
||||
let output_without_from_to = test_env.run_jj_in(&repo_path, ["op", "diff"]);
|
||||
assert_eq!(output, output_without_from_to);
|
||||
|
||||
// Diff from root operation to latest operation
|
||||
let output = test_env.run_jj_in(&repo_path, ["op", "diff", "--from", "0000000"]);
|
||||
@ -1849,8 +1849,8 @@ fn test_op_show() {
|
||||
[EOF]
|
||||
");
|
||||
// `jj op show @` should behave identically to `jj op show`.
|
||||
let output_without_op_id = test_env.run_jj_in(&repo_path, ["op", "show"]).success();
|
||||
assert_eq!(output.stdout.raw(), output_without_op_id.stdout.raw());
|
||||
let output_without_op_id = test_env.run_jj_in(&repo_path, ["op", "show"]);
|
||||
assert_eq!(output, output_without_op_id);
|
||||
|
||||
// Showing a given operation.
|
||||
let output = test_env.run_jj_in(&repo_path, ["op", "show", "@-"]);
|
||||
|
Loading…
x
Reference in New Issue
Block a user