mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-25 05:29:39 +00:00
cli: add test of --no-commit-working-copy
I didn't add a test in #90 because the test cases needed to be cleaned up first. They now look a bit better, so we can add test for the flag.
This commit is contained in:
parent
834349a971
commit
6747a6c59c
2 changed files with 58 additions and 1 deletions
|
@ -55,11 +55,15 @@ impl TestEnvironment {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn get_stdout_string(assert: &assert_cmd::assert::Assert) -> String {
|
||||
String::from_utf8(assert.get_output().stdout.clone()).unwrap()
|
||||
}
|
||||
|
||||
pub fn capture_matches(
|
||||
assert: assert_cmd::assert::Assert,
|
||||
pattern: &str,
|
||||
) -> (assert_cmd::assert::Assert, Vec<String>) {
|
||||
let stdout_string = String::from_utf8(assert.get_output().stdout.clone()).unwrap();
|
||||
let stdout_string = get_stdout_string(&assert);
|
||||
let assert = assert.stdout(predicates::str::is_match(pattern).unwrap());
|
||||
let matches = Regex::new(pattern)
|
||||
.unwrap()
|
||||
|
|
53
tests/test_global_opts.rs
Normal file
53
tests/test_global_opts.rs
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Copyright 2022 Google LLC
|
||||
//
|
||||
// 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 jujutsu::testutils::{get_stdout_string, TestEnvironment};
|
||||
|
||||
#[test]
|
||||
fn test_no_commit_working_copy() {
|
||||
let test_env = TestEnvironment::default();
|
||||
test_env
|
||||
.jj_cmd(test_env.env_root(), &["init", "repo"])
|
||||
.assert()
|
||||
.success();
|
||||
|
||||
let repo_path = test_env.env_root().join("repo");
|
||||
|
||||
std::fs::write(repo_path.join("file"), "initial").unwrap();
|
||||
let assert = test_env
|
||||
.jj_cmd(&repo_path, &["log", "-T", "commit_id"])
|
||||
.assert()
|
||||
.success();
|
||||
let initial_commit_id_hex = get_stdout_string(&assert);
|
||||
|
||||
// Modify the file. With --no-commit-working-copy, we still get the same commit
|
||||
// ID.
|
||||
std::fs::write(repo_path.join("file"), "modified").unwrap();
|
||||
let assert = test_env
|
||||
.jj_cmd(
|
||||
&repo_path,
|
||||
&["log", "-T", "commit_id", "--no-commit-working-copy"],
|
||||
)
|
||||
.assert()
|
||||
.success();
|
||||
let still_initial_commit_id_hex = get_stdout_string(&assert);
|
||||
assert_eq!(still_initial_commit_id_hex, initial_commit_id_hex);
|
||||
// But without --no-commit-working-copy, we get a new commit ID.
|
||||
let assert = test_env
|
||||
.jj_cmd(&repo_path, &["log", "-T", "commit_id"])
|
||||
.assert()
|
||||
.success();
|
||||
let modified_commit_id_hex = get_stdout_string(&assert);
|
||||
assert_ne!(modified_commit_id_hex, initial_commit_id_hex);
|
||||
}
|
Loading…
Reference in a new issue