mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 07:14:38 +00:00
Add tests for the abandon
command
I tested some hairy cases, but didn't add any simpler tests.
This commit is contained in:
parent
9a3329ee25
commit
c43f0a580a
1 changed files with 109 additions and 0 deletions
109
tests/test_abandon_command.rs
Normal file
109
tests/test_abandon_command.rs
Normal file
|
@ -0,0 +1,109 @@
|
|||
// Copyright 2023 The Jujutsu Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// https://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use crate::common::TestEnvironment;
|
||||
|
||||
pub mod common;
|
||||
|
||||
fn create_commit(test_env: &TestEnvironment, repo_path: &Path, name: &str, parents: &[&str]) {
|
||||
if parents.is_empty() {
|
||||
test_env.jj_cmd_success(repo_path, &["new", "root", "-m", name]);
|
||||
} else {
|
||||
let mut args = vec!["new", "-m", name];
|
||||
args.extend(parents);
|
||||
test_env.jj_cmd_success(repo_path, &args);
|
||||
}
|
||||
std::fs::write(repo_path.join(name), format!("{name}\n")).unwrap();
|
||||
test_env.jj_cmd_success(repo_path, &["branch", "create", name]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_rebase_branch_with_merge() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
create_commit(&test_env, &repo_path, "a", &[]);
|
||||
create_commit(&test_env, &repo_path, "b", &["a"]);
|
||||
create_commit(&test_env, &repo_path, "c", &[]);
|
||||
create_commit(&test_env, &repo_path, "d", &["c"]);
|
||||
create_commit(&test_env, &repo_path, "e", &["a", "d"]);
|
||||
// Test the setup
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@ e
|
||||
|\
|
||||
o | d
|
||||
o | c
|
||||
| | o b
|
||||
| |/
|
||||
| o a
|
||||
|/
|
||||
o
|
||||
"###);
|
||||
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "d"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Rebased 1 descendant commits onto parents of abandoned commits
|
||||
Working copy now at: 11a2e10edf4e e
|
||||
Added 0 files, modified 0 files, removed 1 files
|
||||
"###);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@ e
|
||||
|\
|
||||
o | c d
|
||||
| | o b
|
||||
| |/
|
||||
| o a
|
||||
|/
|
||||
o
|
||||
"###);
|
||||
|
||||
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon"] /* abandons `e` */);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Working copy now at: 6b5275139632 (no description set)
|
||||
Added 0 files, modified 0 files, removed 3 files
|
||||
"###);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@
|
||||
| o d e?
|
||||
| o c
|
||||
| | o b
|
||||
| |/
|
||||
|/|
|
||||
o | a e?
|
||||
|/
|
||||
o
|
||||
"###);
|
||||
|
||||
test_env.jj_cmd_success(&repo_path, &["undo"]);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["abandon", "descendants(c)"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
Working copy now at: e7bb061217d5 (no description set)
|
||||
Added 0 files, modified 0 files, removed 3 files
|
||||
"###);
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@
|
||||
| o b
|
||||
|/
|
||||
o a e?
|
||||
o c d e?
|
||||
"###);
|
||||
}
|
||||
|
||||
fn get_log_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
||||
test_env.jj_cmd_success(repo_path, &["log", "-T", "branches"])
|
||||
}
|
Loading…
Reference in a new issue