tests: snapshot a few more colored outputs

This commit is contained in:
Yuya Nishihara 2025-05-17 14:22:21 +09:00
parent 53619359e2
commit f7f85383bc
4 changed files with 126 additions and 1 deletions

View File

@ -1596,6 +1596,22 @@ fn test_bookmark_list() {
[EOF]
");
let output = local_dir.run_jj(["bookmark", "list", "--all-remotes", "--color=always"]);
insta::assert_snapshot!(output, @r"
local-only: wqnwkozp 0353dd35 (empty) local-only
remote-delete (deleted)
@origin: vruxwmqv b32031cf (empty) remote-delete
remote-sync: rlvkpnrz 7a07dbee (empty) remote-sync
@origin: rlvkpnrz 7a07dbee (empty) remote-sync
remote-unsync: wqnwkozp 0353dd35 (empty) local-only
@origin (ahead by 1 commits, behind by 1 commits): zsuskuln 553203ba (empty) remote-unsync
remote-untrack@origin: royxmykx 149bc756 (empty) remote-untrack
[EOF]
------- stderr -------
Hint: Bookmarks marked as deleted can be *deleted permanently* on the remote by running `jj git push --deleted`. Use `jj bookmark forget` if you don't want that.
[EOF]
");
let template = r#"
concat(
"[" ++ name ++ if(remote, "@" ++ remote) ++ "]\n",

View File

@ -305,6 +305,61 @@ fn test_git_import_move_export_with_default_undo() {
");
}
#[test]
fn test_git_import_export_stats_color() {
let test_env = TestEnvironment::default();
test_env.run_jj_in(".", ["git", "init", "repo"]).success();
let work_dir = test_env.work_dir("repo");
let git_repo = git::open(work_dir.root().join(".jj/repo/store/git"));
work_dir.run_jj(["bookmark", "set", "-r@", "foo"]).success();
work_dir
.run_jj(["bookmark", "set", "-r@", "'un:exportable'"])
.success();
work_dir.run_jj(["new", "--no-edit", "root()"]).success();
let other_commit_id = work_dir
.run_jj(&["log", "-Tcommit_id", "--no-graph", "-rvisible_heads() ~ @"])
.success()
.stdout
.into_raw();
let output = work_dir
.run_jj(["git", "export", "--color=always"])
.success();
insta::assert_snapshot!(output, @r#"
------- stderr -------
Warning: Failed to export some bookmarks:
"un:exportable"@git: Failed to set: A reference must be a valid tag name as well: A ref must not contain invalid bytes or ascii control characters: ":"
Hint: Git doesn't allow a branch name that looks like a parent directory of
another (e.g. `foo` and `foo/bar`). Try to rename the bookmarks that failed to
export or their "parent" bookmarks.
[EOF]
"#);
let other_commit_id = gix::ObjectId::from_hex(other_commit_id.as_bytes()).unwrap();
for name in ["refs/heads/foo", "refs/heads/bar", "refs/tags/baz"] {
git_repo
.reference(
name,
other_commit_id,
gix::refs::transaction::PreviousValue::Any,
"",
)
.unwrap();
}
let output = work_dir
.run_jj(["git", "import", "--color=always"])
.success();
insta::assert_snapshot!(output, @r"
------- stderr -------
bookmark: bar@git [new] tracked
bookmark: foo@git [updated] tracked
tag: baz@git [new]
[EOF]
");
}
#[must_use]
fn get_bookmark_output(work_dir: &TestWorkDir) -> CommandOutput {
work_dir.run_jj(["bookmark", "list", "--all-remotes"])

View File

@ -318,6 +318,20 @@ fn test_git_push_forward_unexpectedly_moved() {
[EOF]
[exit status: 1]
");
// The ref name should be colorized
let output = work_dir.run_jj(["git", "push", "--color=always"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Changes to push to origin:
Move forward bookmark bookmark1 from 9b2e76de3920 to 624f94a35f00
Error: Failed to push some bookmarks
Hint: The following references unexpectedly moved on the remote:
 refs/heads/bookmark1 (reason: stale info)
Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
[EOF]
[exit status: 1]
");
}
#[test]
@ -370,6 +384,20 @@ fn test_git_push_sideways_unexpectedly_moved() {
[EOF]
[exit status: 1]
");
// The ref name should be colorized
let output = work_dir.run_jj(["git", "push", "--color=always"]);
insta::assert_snapshot!(output, @r"
------- stderr -------
Changes to push to origin:
Move sideways bookmark bookmark1 from 9b2e76de3920 to 827b8a385853
Error: Failed to push some bookmarks
Hint: The following references unexpectedly moved on the remote:
 refs/heads/bookmark1 (reason: stale info)
Hint: Try fetching from the remote, then make the bookmark point to where you want it to be, and push again.
[EOF]
[exit status: 1]
");
}
// This tests whether the push checks that the remote bookmarks are in expected

View File

@ -105,6 +105,32 @@ fn test_op_log() {
[EOF]
");
let output = work_dir.run_jj(["op", "log", "--op-diff", "--color=always"]);
insta::assert_snapshot!(output, @r"
@ 09a518cf68a5 test-username@host.example.com 2001-02-03 04:05:08.000 +07:00 - 2001-02-03 04:05:08.000 +07:00
describe commit e8849ae12c709f2321908879bc724fdb2ab8a781
args: jj describe -m 'description 0'
Changed commits:
+ qpvuntsm 3ae22e7f (empty) description 0
- qpvuntsm hidden e8849ae1 (empty) (no description set)
Changed working copy default@:
+ qpvuntsm 3ae22e7f (empty) description 0
- qpvuntsm hidden e8849ae1 (empty) (no description set)
2affa7025254 test-username@host.example.com 2001-02-03 04:05:07.000 +07:00 - 2001-02-03 04:05:07.000 +07:00
add workspace 'default'
Changed commits:
+ qpvuntsm e8849ae1 (empty) (no description set)
Changed working copy default@:
+ qpvuntsm e8849ae1 (empty) (no description set)
- (absent)
000000000000 root()
[EOF]
");
work_dir
.run_jj(["describe", "-m", "description 1"])
.success();
@ -120,7 +146,7 @@ fn test_op_log() {
insta::assert_snapshot!(work_dir.run_jj(["log", "--at-op", "@-"]), @r#"
------- stderr -------
Error: The "@" expression resolved to more than one operation
Hint: Try specifying one of the operations by ID: ad1b3bd7fb02, 9e17e47612d5
Hint: Try specifying one of the operations by ID: ca1431ae8aca, f392182c5ff4
[EOF]
[exit status: 1]
"#);