Skip to content

Commit

Permalink
Fix issues with the jj next and jj prev tests
Browse files Browse the repository at this point in the history
  • Loading branch information
emesterhazy committed Apr 2, 2024
1 parent e5b9e8f commit 1cbea78
Showing 1 changed file with 51 additions and 7 deletions.
58 changes: 51 additions & 7 deletions cli/tests/test_next_prev_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// limitations under the License.
//

use std::path::Path;

use crate::common::{get_stderr_string, get_stdout_string, TestEnvironment};

#[test]
Expand Down Expand Up @@ -220,6 +222,17 @@ fn test_prev_fails_on_merge_commit() {
test_env.jj_cmd_ok(&repo_path, &["branch", "c", "right"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["new", "left", "right"]);

// Check that the graph looks the way we expect.
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ yqosqzytrlsw
├─╮
│ ◉ zsuskulnrvyr right second
◉ │ qpvuntsmwlqt left first
├─╯
◉ zzzzzzzzzzzz
"###);

// Try to advance the working copy commit.
let stderr = test_env.jj_cmd_failure(&repo_path, &["prev"]);
insta::assert_snapshot!(stderr,@r###"
Expand All @@ -240,7 +253,21 @@ fn test_prev_fails_on_multiple_parents() {
// Create a merge commit, which has two parents.
test_env.jj_cmd_ok(&repo_path, &["new", "all:@--+"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "merge"]);
// Advance the working copy commit.

// Check that the graph looks the way we expect.
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ vruxwmqvtpmx
◉ yqosqzytrlsw merge
├─┬─╮
│ │ ◉ qpvuntsmwlqt first
│ ◉ │ kkmpptxzrspx second
│ ├─╯
◉ │ mzvwutvlkqwt third
├─╯
◉ zzzzzzzzzzzz
"###);

// Move @ backwards.
let (stdout, stderr) = test_env.jj_cmd_stdin_ok(&repo_path, &["prev"], "3\n");
insta::assert_snapshot!(stdout,@r###"
ambiguous prev commit, choose one to target:
Expand All @@ -251,7 +278,7 @@ fn test_prev_fails_on_multiple_parents() {
enter the index of the commit you want to target:
"###);
insta::assert_snapshot!(stderr,@r###"
Working copy now at: yostqsxw 286a9951 (empty) (no description set)
Working copy now at: znkkpsqq 94715f3c (empty) (no description set)
Parent commit : qpvuntsm 69542c19 (empty) first
"###);
}
Expand Down Expand Up @@ -282,18 +309,30 @@ fn test_prev_editing() {
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "second"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "third"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "fourth"]);
// Edit the "fourth" commit, which becomes the tip when the empty @ commit
// is dropped.
test_env.jj_cmd_ok(&repo_path, &["edit", "@-"]);
// Check that the graph looks the way we expect.
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ zsuskulnrvyr fourth
◉ kkmpptxzrspx third
◉ rlvkpnrzqnoo second
◉ qpvuntsmwlqt first
◉ zzzzzzzzzzzz
"###);

let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["prev", "--edit"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stdout, @r"");
insta::assert_snapshot!(stderr, @r###"
Working copy now at: zsuskuln 009f88bf (empty) fourth
Parent commit : kkmpptxz 3fa8931e (empty) third
Working copy now at: kkmpptxz 3fa8931e (empty) third
Parent commit : rlvkpnrz 5c52832c (empty) second
"###);
// --edit is implied when already editing a non-head commit
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["prev"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Working copy now at: yqosqzyt d2edc95b (empty) (no description set)
Parent commit : rlvkpnrz 5c52832c (empty) second
Working copy now at: rlvkpnrz 5c52832c (empty) second
Parent commit : qpvuntsm 69542c19 (empty) first
"###);
}

Expand Down Expand Up @@ -322,3 +361,8 @@ fn test_next_editing() {
Parent commit : kkmpptxz 3fa8931e (empty) third
"###);
}

fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
let template = r#"separate(" ", change_id.short(), local_branches, description)"#;
test_env.jj_cmd_success(cwd, &["log", "-T", template])
}

0 comments on commit 1cbea78

Please sign in to comment.