forked from mirrors/jj
080a9b37ff
Perhaps it makes more sense to display the working copy commit just above the changes in the working copy commit, even though that means that the order between the working copy commit and the parent becomes the opposite of the order in `jj log`.
112 lines
3.6 KiB
Rust
112 lines
3.6 KiB
Rust
// Copyright 2020 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;
|
|
use regex::Regex;
|
|
|
|
#[test]
|
|
fn smoke_test() {
|
|
let temp_dir = tempfile::tempdir().unwrap();
|
|
|
|
let output = testutils::CommandRunner::new(temp_dir.path()).run(vec!["init", "repo"]);
|
|
assert_eq!(output.status, 0);
|
|
let repo_path = temp_dir.path().join("repo");
|
|
|
|
// Check the output of `jj status` right after initializing repo
|
|
let output = testutils::CommandRunner::new(&repo_path).run(vec!["status"]);
|
|
assert_eq!(output.status, 0);
|
|
let stdout_string = output.stdout_string();
|
|
let output_regex = Regex::new(
|
|
"^Parent commit: 000000000000 \n\
|
|
Working copy : ([[:xdigit:]]+) \n\
|
|
The working copy is clean\n\
|
|
$",
|
|
)
|
|
.unwrap();
|
|
assert!(
|
|
output_regex.is_match(&stdout_string),
|
|
"output was: {}",
|
|
stdout_string
|
|
);
|
|
let wc_hex_id_empty = output_regex
|
|
.captures(&stdout_string)
|
|
.unwrap()
|
|
.get(1)
|
|
.unwrap()
|
|
.as_str()
|
|
.to_owned();
|
|
|
|
// Write some files and check the output of `jj status`
|
|
std::fs::write(repo_path.join("file1"), "file1").unwrap();
|
|
std::fs::write(repo_path.join("file2"), "file2").unwrap();
|
|
std::fs::write(repo_path.join("file3"), "file3").unwrap();
|
|
|
|
let output = testutils::CommandRunner::new(&repo_path).run(vec!["status"]);
|
|
assert_eq!(output.status, 0);
|
|
let stdout_string = output.stdout_string();
|
|
let output_regex = Regex::new(
|
|
"^Parent commit: 000000000000 \n\
|
|
Working copy : ([[:xdigit:]]+) \n\
|
|
Working copy changes:\n\
|
|
A file1\n\
|
|
A file2\n\
|
|
A file3\n\
|
|
$",
|
|
)
|
|
.unwrap();
|
|
assert!(
|
|
output_regex.is_match(&stdout_string),
|
|
"output was: {}",
|
|
stdout_string
|
|
);
|
|
let wc_hex_id_non_empty = output_regex
|
|
.captures(&stdout_string)
|
|
.unwrap()
|
|
.get(1)
|
|
.unwrap()
|
|
.as_str()
|
|
.to_owned();
|
|
|
|
// The working copy's id should have changed
|
|
assert_ne!(wc_hex_id_empty, wc_hex_id_non_empty);
|
|
|
|
// Running `jj status` again gives the same output
|
|
let output2 = testutils::CommandRunner::new(&repo_path).run(vec!["status"]);
|
|
assert_eq!(output, output2);
|
|
|
|
// Add a commit description
|
|
let output =
|
|
testutils::CommandRunner::new(&repo_path).run(vec!["describe", "-m", "add some files"]);
|
|
assert_eq!(output.status, 0);
|
|
let stdout_string = output.stdout_string();
|
|
let output_regex =
|
|
Regex::new("^Leaving: [[:xdigit:]]+ \nNow at: [[:xdigit:]]+ add some files\n$").unwrap();
|
|
assert!(
|
|
output_regex.is_match(&stdout_string),
|
|
"output was: {}",
|
|
stdout_string
|
|
);
|
|
|
|
// Close the commit
|
|
let output = testutils::CommandRunner::new(&repo_path).run(vec!["close"]);
|
|
assert_eq!(output.status, 0);
|
|
let stdout_string = output.stdout_string();
|
|
let output_regex =
|
|
Regex::new("^Leaving: [[:xdigit:]]+ add some files\nNow at: [[:xdigit:]]+ \n$").unwrap();
|
|
assert!(
|
|
output_regex.is_match(&stdout_string),
|
|
"output was: {}",
|
|
stdout_string
|
|
);
|
|
}
|