Skip to content

Commit

Permalink
test_describe_command: add simple demo of bug 2600
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Dec 1, 2023
1 parent bb72def commit 39697de
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cli/tests/test_describe_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::Path;

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

pub mod common;
Expand Down Expand Up @@ -173,6 +175,46 @@ fn test_describe() {
assert!(get_stderr_string(&assert).contains("bad-jj-editor-from-jj-editor-env"));
}

// https://github.com/martinvonz/jj/issues/2600
#[test]
fn test_bug_2600() {
let test_env = TestEnvironment::default();
test_env.jj_cmd_ok(test_env.env_root(), &["init", "repo", "--git"]);
let repo_path = test_env.env_root().join("repo");

create_commit(&test_env, &repo_path, "base", &[]);
create_commit(&test_env, &repo_path, "a", &["base"]);
create_commit(&test_env, &repo_path, "b", &["base", "a"]);
create_commit(&test_env, &repo_path, "c", &["b"]);

// Test the setup
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ c
◉ b
├─╮
│ ◉ a
├─╯
◉ base
"###);

let (stdout, stderr) =
test_env.jj_cmd_ok(&repo_path, &["describe", "-r", "a", "-m", "newname"]);
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Rebased 2 descendant commits
Working copy now at: vruxwmqv 6a9375ce c | c
Parent commit : royxmykx 26ffdee4 b | b
"###);
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
@ c
◉ b
◉ newname
◉ base
"###);
}

#[test]
fn test_multiple_message_args() {
let test_env = TestEnvironment::default();
Expand Down Expand Up @@ -325,3 +367,19 @@ fn test_describe_author() {
~
"###);
}

fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
if parents.is_empty() {
test_env.jj_cmd_ok(repo_path, &["new", "root()", "-m", name]);
} else {
let mut args = vec!["new", "-m", name];
args.extend(parents);
test_env.jj_cmd_ok(repo_path, &args);
}
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
test_env.jj_cmd_ok(repo_path, &["branch", "create", name]);
}

fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
test_env.jj_cmd_success(repo_path, &["log", "-T", "description"])
}

0 comments on commit 39697de

Please sign in to comment.