2022-04-09 22:53:32 +00:00
|
|
|
// 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.
|
|
|
|
|
2022-04-09 22:53:32 +00:00
|
|
|
use crate::common::{get_stderr_string, TestEnvironment};
|
2022-04-09 22:53:32 +00:00
|
|
|
|
|
|
|
pub mod common;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_describe() {
|
|
|
|
let mut 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");
|
|
|
|
|
|
|
|
let edit_script = test_env.set_up_fake_editor();
|
|
|
|
|
|
|
|
// Set a description using `-m` flag
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["describe", "-m", "description from CLI"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: 7e0db3b0ad17 description from CLI
|
|
|
|
"###);
|
2022-04-09 22:53:32 +00:00
|
|
|
|
|
|
|
// Test making no changes
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: 45bfa10db64d description from CLI
|
|
|
|
"###);
|
2022-04-09 22:53:32 +00:00
|
|
|
|
|
|
|
// Set a description in editor
|
|
|
|
std::fs::write(&edit_script, "write\ndescription from editor").unwrap();
|
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: f2ce8f1ad8fa description from editor
|
|
|
|
"###);
|
2022-04-09 22:53:32 +00:00
|
|
|
|
|
|
|
// Lines in editor starting with "JJ: " are ignored
|
2022-04-09 22:53:32 +00:00
|
|
|
std::fs::write(
|
|
|
|
&edit_script,
|
|
|
|
"write\nJJ: ignored\ndescription among comment\nJJ: ignored",
|
|
|
|
)
|
|
|
|
.unwrap();
|
2022-04-09 22:53:32 +00:00
|
|
|
let stdout = test_env.jj_cmd_success(&repo_path, &["describe"]);
|
2022-04-28 23:32:18 +00:00
|
|
|
insta::assert_snapshot!(stdout, @r###"
|
|
|
|
Working copy now at: 95664f6316ae description among comment
|
|
|
|
"###);
|
2022-04-09 22:53:32 +00:00
|
|
|
|
|
|
|
// Fails if the editor fails
|
|
|
|
std::fs::write(&edit_script, "fail").unwrap();
|
|
|
|
let stderr = test_env.jj_cmd_failure(&repo_path, &["describe"]);
|
|
|
|
assert!(stderr.contains("exited with an error"));
|
|
|
|
|
|
|
|
// Fails if the editor doesn't exist
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(&repo_path, &["describe"])
|
|
|
|
.env("EDITOR", "this-editor-does-not-exist")
|
|
|
|
.assert()
|
|
|
|
.failure();
|
|
|
|
assert!(get_stderr_string(&assert).contains("Failed to run"));
|
2022-04-10 05:42:27 +00:00
|
|
|
|
|
|
|
// `ui.editor` config overrides `$EDITOR`
|
|
|
|
std::fs::write(&edit_script, "").unwrap();
|
|
|
|
test_env.add_config(
|
|
|
|
br#"[ui]
|
|
|
|
editor = "bad-editor-from-config""#,
|
|
|
|
);
|
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(&repo_path, &["describe"])
|
|
|
|
.env("EDITOR", "bad-editor-from-env")
|
|
|
|
.assert()
|
|
|
|
.failure();
|
|
|
|
assert!(get_stderr_string(&assert).contains("bad-editor-from-config"));
|
2022-04-10 06:20:36 +00:00
|
|
|
|
|
|
|
// `$JJ_EDITOR` overrides `ui.editor` config
|
|
|
|
let assert = test_env
|
|
|
|
.jj_cmd(&repo_path, &["describe"])
|
|
|
|
.env("JJ_EDITOR", "bad-jj-editor-from-env")
|
|
|
|
.assert()
|
|
|
|
.failure();
|
|
|
|
assert!(get_stderr_string(&assert).contains("bad-jj-editor-from-env"));
|
2022-04-09 22:53:32 +00:00
|
|
|
}
|