just playing with tangled
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

tests: migrate unusual patterns of jj_cmd_ok() to run_jj_in()

These callers are manually ported to run_jj_in().

+60 -59
-20
cli/tests/common/test_environment.rs
··· 29 29 30 30 use super::fake_diff_editor_path; 31 31 use super::fake_editor_path; 32 - use super::get_stderr_string; 33 - use super::get_stdout_string; 34 32 use super::strip_last_line; 35 33 use super::to_toml_value; 36 34 ··· 151 149 } 152 150 153 151 cmd 154 - } 155 - 156 - fn get_ok(&self, mut cmd: assert_cmd::Command) -> (CommandOutputString, CommandOutputString) { 157 - let assert = cmd.assert().success(); 158 - let stdout = self.normalize_output(get_stdout_string(&assert)); 159 - let stderr = self.normalize_output(get_stderr_string(&assert)); 160 - (stdout, stderr) 161 - } 162 - 163 - /// Run a `jj` command, check that it was successful, and return its 164 - /// `(stdout, stderr)`. 165 - // TODO: remove jj_cmd_*() in favor of run_jj_*() 166 - pub fn jj_cmd_ok( 167 - &self, 168 - current_dir: &Path, 169 - args: &[&str], 170 - ) -> (CommandOutputString, CommandOutputString) { 171 - self.get_ok(self.jj_cmd(current_dir, args)) 172 152 } 173 153 174 154 pub fn env_root(&self) -> &Path {
+4 -2
cli/tests/test_bookmark_command.rs
··· 519 519 let repo_path = test_env.env_root().join("repo"); 520 520 let get_log = || { 521 521 let template = r#"separate(" ", description.first_line(), bookmarks)"#; 522 - let (stdout, _stderr) = test_env.jj_cmd_ok(&repo_path, &["log", "-T", template]); 523 - stdout 522 + test_env.run_jj_in(&repo_path, ["log", "-T", template]) 524 523 }; 525 524 526 525 test_env ··· 563 562 │ ○ B0 foo?? 564 563 ├─╯ 565 564 565 + [EOF] 566 + ------- stderr ------- 567 + Concurrent modification detected, resolving automatically. 566 568 [EOF] 567 569 "); 568 570
+7 -2
cli/tests/test_config_command.rs
··· 1498 1498 log_cmd.env_remove("JJ_EMAIL"); 1499 1499 log_cmd.assert().success(); 1500 1500 1501 - let (stdout, _) = test_env.jj_cmd_ok(&repo_path, &["log"]); 1502 - assert!(stdout.raw().contains("Foo")); 1501 + let output = test_env.run_jj_in(&repo_path, ["log"]); 1502 + insta::assert_snapshot!(output, @r" 1503 + @ qpvuntsm Foo 2001-02-03 08:05:09 ed1febd8 1504 + │ (empty) (no description set) 1505 + ◆ zzzzzzzz root() 00000000 1506 + [EOF] 1507 + "); 1503 1508 } 1504 1509 1505 1510 #[test]
+4 -4
cli/tests/test_diff_command.rs
··· 2231 2231 2232 2232 // nonzero exit codes should print a warning 2233 2233 std::fs::write(&edit_script, "fail").unwrap(); 2234 - let (stdout, stderr) = test_env.jj_cmd_ok( 2234 + let output = test_env.run_jj_in( 2235 2235 &repo_path, 2236 - &["diff", "--config=ui.diff.tool=fake-diff-editor"], 2236 + ["diff", "--config=ui.diff.tool=fake-diff-editor"], 2237 2237 ); 2238 2238 let mut insta_settings = insta::Settings::clone_current(); 2239 2239 insta_settings.add_filter("exit (status|code)", "<exit status>"); 2240 2240 insta_settings.bind(|| { 2241 - insta::assert_snapshot!(stdout, @r""); 2242 - insta::assert_snapshot!(stderr, @r" 2241 + insta::assert_snapshot!(output, @r" 2242 + ------- stderr ------- 2243 2243 Warning: Tool exited with <exit status>: 1 (run with --debug to see the exact invocation) 2244 2244 [EOF] 2245 2245 ");
+3 -4
cli/tests/test_git_colocated.rs
··· 509 509 test_env 510 510 .run_jj_in(&workspace_root, ["bookmark", "create", "-r@", "main"]) 511 511 .success(); 512 - let (stdout, stderr) = 513 - test_env.jj_cmd_ok(&workspace_root, &["bookmark", "create", "-r@", "main/sub"]); 514 - insta::assert_snapshot!(stdout, @""); 512 + let output = test_env.run_jj_in(&workspace_root, ["bookmark", "create", "-r@", "main/sub"]); 515 513 insta::with_settings!({filters => vec![("Failed to set: .*", "Failed to set: ...")]}, { 516 - insta::assert_snapshot!(stderr, @r#" 514 + insta::assert_snapshot!(output, @r#" 515 + ------- stderr ------- 517 516 Created 1 bookmarks pointing to qpvuntsm 230dd059 main main/sub | (empty) (no description set) 518 517 Warning: Failed to export some bookmarks: 519 518 main/sub: Failed to set: ...
+3 -3
cli/tests/test_git_import_export.rs
··· 81 81 test_env 82 82 .run_jj_in(&repo_path, ["bookmark", "create", "-r@", "main/sub"]) 83 83 .success(); 84 - let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, &["git", "export"]); 85 - insta::assert_snapshot!(stdout, @""); 84 + let output = test_env.run_jj_in(&repo_path, ["git", "export"]); 86 85 insta::with_settings!({filters => vec![("Failed to set: .*", "Failed to set: ...")]}, { 87 - insta::assert_snapshot!(stderr, @r#" 86 + insta::assert_snapshot!(output, @r#" 87 + ------- stderr ------- 88 88 Warning: Failed to export some bookmarks: 89 89 main/sub: Failed to set: ... 90 90 Hint: Git doesn't allow a branch name that looks like a parent directory of
+18 -4
cli/tests/test_operations.rs
··· 1236 1236 ], 1237 1237 ) 1238 1238 .success(); 1239 - let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["log"]); 1240 - insta::assert_snapshot!(&stderr, @r" 1239 + let output = test_env.run_jj_in(&repo_path, ["log"]); 1240 + insta::assert_snapshot!(output, @r" 1241 + @ sqpuoqvx test.user@example.com 2001-02-03 08:05:07 c7b48fea 1242 + │ (empty) (no description set) 1243 + ◆ pukowqtp someone@example.org 1970-01-01 11:00:00 bookmark-1?? bookmark-1@origin 0cb7e07e 1244 + │ Commit 1 1245 + ~ 1246 + [EOF] 1247 + ------- stderr ------- 1241 1248 Concurrent modification detected, resolving automatically. 1242 1249 [EOF] 1243 1250 "); ··· 1985 1992 ], 1986 1993 ) 1987 1994 .success(); 1988 - let (_, stderr) = test_env.jj_cmd_ok(&repo_path, &["log"]); 1989 - insta::assert_snapshot!(&stderr, @r" 1995 + let output = test_env.run_jj_in(&repo_path, ["log"]); 1996 + insta::assert_snapshot!(output, @r" 1997 + @ sqpuoqvx test.user@example.com 2001-02-03 08:05:07 c7b48fea 1998 + │ (empty) (no description set) 1999 + ◆ pukowqtp someone@example.org 1970-01-01 11:00:00 bookmark-1?? bookmark-1@origin 0cb7e07e 2000 + │ Commit 1 2001 + ~ 2002 + [EOF] 2003 + ------- stderr ------- 1990 2004 Concurrent modification detected, resolving automatically. 1991 2005 [EOF] 1992 2006 ");
+6 -10
cli/tests/test_shell_completion.rs
··· 12 12 // See the License for the specific language governing permissions and 13 13 // limitations under the License. 14 14 15 - use insta::assert_snapshot; 16 - 17 15 use crate::common::TestEnvironment; 18 16 19 17 #[test] 20 18 fn test_deprecated_flags() { 21 19 let test_env = TestEnvironment::default(); 22 - let (stdout, stderr) = 23 - test_env.jj_cmd_ok(test_env.env_root(), &["util", "completion", "--bash"]); 24 - assert_snapshot!( 25 - stderr, 26 - @r" 20 + let output = test_env 21 + .run_jj_in(test_env.env_root(), ["util", "completion", "--bash"]) 22 + .success(); 23 + insta::assert_snapshot!(output.stderr, @r" 27 24 Warning: `jj util completion --bash` will be removed in a future version, and this will be a hard error 28 25 Hint: Use `jj util completion bash` instead 29 26 [EOF] 30 - " 31 - ); 32 - assert!(stdout.raw().contains("COMPREPLY")); 27 + "); 28 + assert!(output.stdout.raw().contains("COMPREPLY"), "{output}"); 33 29 }
+5 -3
cli/tests/test_split_command.rs
··· 955 955 ["", "next invocation\n", "write\nsecond-commit"].join("\0"), 956 956 ) 957 957 .unwrap(); 958 - let (_, stderr) = test_env.jj_cmd_ok(&main_path, &["split", "file2"]); 958 + let output = test_env.run_jj_in(&main_path, ["split", "file2"]); 959 959 match bookmark_behavior { 960 960 BookmarkBehavior::Default | BookmarkBehavior::Modern => { 961 961 insta::allow_duplicates! { 962 - insta::assert_snapshot!(stderr, @r" 962 + insta::assert_snapshot!(output, @r" 963 + ------- stderr ------- 963 964 First part: qpvuntsm 63d0c5ed *le-signet* | first-commit 964 965 Second part: mzvwutvl a9f5665f second-commit 965 966 Working copy now at: mzvwutvl a9f5665f second-commit ··· 978 979 } 979 980 BookmarkBehavior::Legacy => { 980 981 insta::allow_duplicates! { 981 - insta::assert_snapshot!(stderr, @r" 982 + insta::assert_snapshot!(output, @r" 983 + ------- stderr ------- 982 984 Warning: `jj split` will leave bookmarks on the first commit in the next release. 983 985 Warning: Run `jj config set --user split.legacy-bookmark-behavior false` to silence this message and use the new behavior. 984 986 Warning: See https://github.com/jj-vcs/jj/issues/3419
+10 -7
cli/tests/test_util_command.rs
··· 124 124 fn test(shell: &str) { 125 125 let test_env = TestEnvironment::default(); 126 126 // Use the local backend because GitBackend::gc() depends on the git CLI. 127 - let (out, err) = test_env.jj_cmd_ok(test_env.env_root(), &["util", "completion", shell]); 127 + let output = test_env 128 + .run_jj_in(test_env.env_root(), ["util", "completion", shell]) 129 + .success(); 128 130 // Ensures only stdout contains text 129 - assert!(!out.is_empty()); 130 - assert!(err.is_empty()); 131 + assert!( 132 + !output.stdout.is_empty() && output.stderr.is_empty(), 133 + "{output}" 134 + ); 131 135 } 132 136 133 137 test("bash"); ··· 140 144 fn test_util_exec() { 141 145 let test_env = TestEnvironment::default(); 142 146 let formatter_path = assert_cmd::cargo::cargo_bin("fake-formatter"); 143 - let (out, err) = test_env.jj_cmd_ok( 147 + let output = test_env.run_jj_in( 144 148 test_env.env_root(), 145 - &[ 149 + [ 146 150 "util", 147 151 "exec", 148 152 "--", ··· 151 155 "hello", 152 156 ], 153 157 ); 154 - insta::assert_snapshot!(out, @"hello[EOF]"); 155 158 // Ensures only stdout contains text 156 - assert!(err.is_empty()); 159 + insta::assert_snapshot!(output, @"hello[EOF]"); 157 160 } 158 161 159 162 #[test]