Debian Codegraph @

cli/tests/common/mod.rs

raw
1 // Copyright 2020 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 mod command_output;
16 mod config_schema_defaults;
17 mod test_environment;
18
19 pub use self::command_output::CommandOutput;
20 pub use self::config_schema_defaults::default_config_from_schema;
21 pub use self::test_environment::TestEnvironment;
22 pub use self::test_environment::TestWorkDir;
23
24 pub fn fake_bisector_path() -> String {
25 let path = assert_cmd::cargo::cargo_bin!("fake-bisector");
26 assert!(path.is_file());
27 path.as_os_str().to_str().unwrap().to_owned()
28 }
29
30 pub fn fake_editor_path() -> String {
31 let path = assert_cmd::cargo::cargo_bin!("fake-editor");
32 assert!(path.is_file());
33 path.as_os_str().to_str().unwrap().to_owned()
34 }
35
36 pub fn fake_diff_editor_path() -> String {
37 let path = assert_cmd::cargo::cargo_bin!("fake-diff-editor");
38 assert!(path.is_file());
39 path.as_os_str().to_str().unwrap().to_owned()
40 }
41
42 /// Forcibly enable interactive prompt.
43 pub fn force_interactive(cmd: &mut assert_cmd::Command) -> &mut assert_cmd::Command {
44 cmd.env("JJ_INTERACTIVE", "1")
45 }
46
47 /// Coerces the value type to serialize it as TOML.
48 pub fn to_toml_value(value: impl Into<toml_edit::Value>) -> toml_edit::Value {
49 value.into()
50 }
51
52 pub fn create_commit(work_dir: &TestWorkDir, name: &str, parents: &[&str]) {
53 create_commit_with_files(work_dir, name, parents, &[(name, &format!("{name}\n"))]);
54 }
55
56 pub fn create_commit_with_files(
57 work_dir: &TestWorkDir,
58 name: &str,
59 parents: &[&str],
60 files: &[(&str, &str)],
61 ) {
62 let parents = match parents {
63 [] => &["root()"],
64 parents => parents,
65 };
66 work_dir
67 .run_jj_with(|cmd| cmd.args(["new", "-m", name]).args(parents))
68 .success();
69 for (name, content) in files {
70 work_dir.write_file(name, content);
71 }
72 work_dir
73 .run_jj(["bookmark", "create", "-r@", name])
74 .success();
75 }