mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-28 07:20:11 +00:00
backout: add initial tests
This commit is contained in:
parent
44a39017f0
commit
456356aacb
2 changed files with 83 additions and 0 deletions
|
@ -12,6 +12,7 @@ mod test_abandon_command;
|
|||
mod test_acls;
|
||||
mod test_advance_branches;
|
||||
mod test_alias;
|
||||
mod test_backout_command;
|
||||
mod test_branch_command;
|
||||
mod test_builtin_aliases;
|
||||
mod test_checkout;
|
||||
|
|
82
cli/tests/test_backout_command.rs
Normal file
82
cli/tests/test_backout_command.rs
Normal file
|
@ -0,0 +1,82 @@
|
|||
// Copyright 2024 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;
|
||||
|
||||
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]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backout() {
|
||||
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, "a", &[]);
|
||||
// Test the setup
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
@ 2443ea76b0b1 a
|
||||
◉ 000000000000
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
A a
|
||||
"###);
|
||||
|
||||
// Backout the commit
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["backout", "-r", "@"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
◉ 8fe4e9345020 backout of commit 2443ea76b0b1c531326908326aab7020abab8e6c
|
||||
@ 2443ea76b0b1 a
|
||||
◉ 000000000000
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@+"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
D a
|
||||
"###);
|
||||
|
||||
// Backout the new backed-out commit
|
||||
test_env.jj_cmd_ok(&repo_path, &["edit", "@+"]);
|
||||
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["backout", "-r", "@"]);
|
||||
insta::assert_snapshot!(stdout, @"");
|
||||
insta::assert_snapshot!(stderr, @"");
|
||||
insta::assert_snapshot!(get_log_output(&test_env, &repo_path), @r###"
|
||||
◉ 46f192066e5e backout of commit 8fe4e93450209a70a6b9cd9af612e86634fd31fd
|
||||
@ 8fe4e9345020 backout of commit 2443ea76b0b1c531326908326aab7020abab8e6c
|
||||
◉ 2443ea76b0b1 a
|
||||
◉ 000000000000
|
||||
"###);
|
||||
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s", "-r", "@+"]);
|
||||
insta::assert_snapshot!(stdout, @r###"
|
||||
A a
|
||||
"###);
|
||||
}
|
||||
|
||||
fn get_log_output(test_env: &TestEnvironment, cwd: &Path) -> String {
|
||||
let template = r#"commit_id.short() ++ " " ++ description"#;
|
||||
test_env.jj_cmd_success(cwd, &["log", "-T", template])
|
||||
}
|
Loading…
Reference in a new issue