// Copyright 2022 The Jujutsu Authors//// 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 testutils::TestResult; use crate::common::CommandOutput;use crate::common::TestEnvironment;use crate::common::TestWorkDir;use crate::common::create_commit;use crate::common::fake_bisector_path; #[test]fn test_bisect_run_missing_command() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=.."]), @" ------- stderr ------- Error: Command argument is required [EOF] [exit status: 2] ");} #[test]fn test_bisect_run_empty_revset() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); let bisection_script = test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); std::fs::write(&bisection_script, ["fail"].join("\0"))?; insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=none()", &bisector_path]), @" Search complete. To discard any revisions created during search, run: jj op restore f63ee16f9553 [EOF] ------- stderr ------- Error: Could not find the first bad revision. Was the input range empty? [EOF] [exit status: 1] "); Ok(())} #[test]fn test_bisect_run() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); let bisection_script = test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); std::fs::write(&bisection_script, ["fail"].join("\0"))?; insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--trust-endpoints", &bisector_path]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is bad. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is bad. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first bad revision is: rlvkpnrz 7d980be7 a | a [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Working copy (@) now at: rsllmpnm 5f328bc5 (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ rsllmpnmslon 5f328bc5fde0 '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); // Try with legacy command argument std::fs::write(&bisection_script, ["fail"].join("\0"))?; // Testing only stderr to avoid a variable op id in the stdout. insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--trust-endpoints", "--command", &bisector_path]).success().stderr, @" Warning: `--command` is deprecated; use positional arguments instead: `jj bisect run --range=... -- $FAKE_BISECTOR_PATH` Working copy (@) now at: nkmrtpmo 1601f7b4 (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 2 files, modified 0 files, removed 0 files Working copy (@) now at: ruktrxxu fb9e625c (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ ruktrxxusqqp fb9e625c1023 '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); Ok(())} #[test]// like test_bisect::test_bisect_nonlinear// bisecting over commits 0,1,2,3,4,5,6 with 5 being the first bad commit// this fails because 6 should also be bad!fn test_bisect_run_nonlinear_no_merge() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); // h // |\ // f g // | | // d e // | | // b c // |/ // a create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["a"]); create_commit(&work_dir, "d", &["b"]); create_commit(&work_dir, "e", &["c"]); create_commit(&work_dir, "f", &["d"]); create_commit(&work_dir, "g", &["e"]); create_commit(&work_dir, "h", &["f", "g"]); // rather than complicating fake_bisector, we try and --find-good insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=ancestors(parents(h))", "--find-good", "--", &bisector_path, "--require-file=f"]), @" Pre-bisection check: ensuring this revision is good: kmkuslsw 3548fddf f | f fake-bisector testing commit 3548fddfc5b69ba4c5b78a19c1cc6d39e52e5a22 Pre-bisection check: ensuring this revision is good: lylxulpl 97949f0f g | g fake-bisector testing commit 97949f0f52afedfc72ef44d63d21266bbfc42774 Cannot bisect: this revision was expected to be good, but was bad (exit status: 1) instead. Search complete. To discard any revisions created during search, run: jj op restore 7d0937f0feb3 [EOF] ------- stderr ------- Working copy (@) now at: xznxytkn 08be40de (empty) (no description set) Parent commit (@-) : kmkuslsw 3548fddf f | f Added 0 files, modified 0 files, removed 4 files Working copy (@) now at: smwtzssm fc3a931c (empty) (no description set) Parent commit (@-) : lylxulpl 97949f0f g | g Added 3 files, modified 0 files, removed 3 files Error: Bisection preconditions failed [EOF] [exit status: 1] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ smwtzssmuxzk fc3a931c8da8 '' files: │ ○ nkmrtpmomlro b47137c13576 'h' files: h ╭─┤ ○ │ lylxulplsnyw 97949f0f52af 'g' files: g ○ │ znkkpsqqskkl efcb3d331401 'e' files: e ○ │ royxmykxtrkr 991a7501d660 'c' files: c │ ○ kmkuslswpqwq 3548fddfc5b6 'f' files: f │ ○ vruxwmqvtpmx 01a5f35e756c 'd' files: d │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); Ok(())} // like test_bisect_run_nonlinear_with_merge, but we include the merge commit.// that makes it okay for commit f to be the first bad one.#[test]fn test_bisect_run_nonlinear_with_merge() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); // h // |\ // f g // | | // d e // | | // b c // |/ // a create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["a"]); create_commit(&work_dir, "d", &["b"]); create_commit(&work_dir, "e", &["c"]); create_commit(&work_dir, "f", &["d"]); create_commit(&work_dir, "g", &["e"]); create_commit(&work_dir, "h", &["f", "g"]); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--find-good", "--", &bisector_path, "--require-file=f"]), @" Pre-bisection check: ensuring this revision is good: nkmrtpmo b47137c1 h | h fake-bisector testing commit b47137c135761c932a7d0c1619d6121868eb7df9 Pre-bisection check: ensuring this revision is bad: zzzzzzzz 00000000 (empty) (no description set) fake-bisector testing commit 0000000000000000000000000000000000000000 Bisecting: 7 revisions left to test after this (roughly 3 steps) Now evaluating: vruxwmqv 01a5f35e d | d fake-bisector testing commit 01a5f35e756cec7f8543120aeedcce0d086a2504 The revision is bad. Bisecting: 4 revisions left to test after this (roughly 3 steps) Now evaluating: znkkpsqq efcb3d33 e | e fake-bisector testing commit efcb3d33140196e8aa5157e4c865e9a4c513f8bb The revision is bad. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: kmkuslsw 3548fddf f | f fake-bisector testing commit 3548fddfc5b69ba4c5b78a19c1cc6d39e52e5a22 The revision is good. Search complete. To discard any revisions created during search, run: jj op restore 7d0937f0feb3 The first good revision is: kmkuslsw 3548fddf f | f [EOF] ------- stderr ------- Working copy (@) now at: xznxytkn 8d14f10f (empty) (no description set) Parent commit (@-) : nkmrtpmo b47137c1 h | h Working copy (@) now at: smwtzssm 71beb6f1 (empty) (no description set) Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) Added 0 files, modified 0 files, removed 8 files Working copy (@) now at: zlusorwl 1576a092 (empty) (no description set) Parent commit (@-) : vruxwmqv 01a5f35e d | d Added 3 files, modified 0 files, removed 0 files Working copy (@) now at: ukzzzykq 05f4e27a (empty) (no description set) Parent commit (@-) : znkkpsqq efcb3d33 e | e Added 2 files, modified 0 files, removed 2 files Working copy (@) now at: lqoxyrsk 4967f850 (empty) (no description set) Parent commit (@-) : kmkuslsw 3548fddf f | f Added 3 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ lqoxyrskwpry 4967f85032d5 '' files: │ ○ nkmrtpmomlro b47137c13576 'h' files: h ╭─┤ │ ○ lylxulplsnyw 97949f0f52af 'g' files: g │ ○ znkkpsqqskkl efcb3d331401 'e' files: e │ ○ royxmykxtrkr 991a7501d660 'c' files: c ○ │ kmkuslswpqwq 3548fddfc5b6 'f' files: f ○ │ vruxwmqvtpmx 01a5f35e756c 'd' files: d ○ │ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); Ok(())} #[test]fn test_bisect_run_find_first_good() { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--find-good", "--trust-endpoints", &bisector_path]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is good. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is good. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first good revision is: rlvkpnrz 7d980be7 a | a [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Working copy (@) now at: rsllmpnm 5f328bc5 (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ rsllmpnmslon 5f328bc5fde0 '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] ");} #[test]fn test_bisect_run_missing_bisector() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); let output = work_dir.run_jj([ "bisect", "run", "--range=..", "--trust-endpoints", "nonexistent", ]); if cfg!(unix) { insta::assert_snapshot!(output, @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Error: Failed to run evaluation command Caused by: No such file or directory (os error 2) [EOF] [exit status: 1] "); } else if cfg!(windows) { insta::assert_snapshot!(output, @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Error: Failed to run evaluation command Caused by: program not found [EOF] [exit status: 1] "); }} #[test]fn test_bisect_run_with_args() { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--find-good", "--trust-endpoints", "--", &bisector_path, "--require-file=c"]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is good. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is bad. Bisecting: 1 revisions left to test after this (roughly 1 steps) Now evaluating: zsuskuln 123b4d91 b | b fake-bisector testing commit 123b4d91f6e5e39bfed39bae3bacf9380dc79078 The revision is bad. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first good revision is: royxmykx dffaa0d4 c | c [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Working copy (@) now at: rsllmpnm 5f328bc5 (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files Working copy (@) now at: zqsquwqt 042badd2 (empty) (no description set) Parent commit (@-) : zsuskuln 123b4d91 b | b Added 1 files, modified 0 files, removed 0 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zqsquwqtrvts 042badd28c1d '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c ├─╯ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] ");} #[test]fn test_bisect_run_crash() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); let bisection_script = test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); // bisector crash is equivalent to a failure std::fs::write(&bisection_script, ["crash"].join("\0"))?; insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--trust-endpoints", &bisector_path]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is bad. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is bad. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first bad revision is: rlvkpnrz 7d980be7 a | a [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | cLines 1–500 of 771. Load more
// Copyright 2022 The Jujutsu Authors // // 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 testutils::TestResult; use crate::common::CommandOutput; use crate::common::TestEnvironment; use crate::common::TestWorkDir; use crate::common::create_commit; use crate::common::fake_bisector_path; #[test] fn test_bisect_run_missing_command() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=.."]), @" ------- stderr ------- Error: Command argument is required [EOF] [exit status: 2] "); } #[test] fn test_bisect_run_empty_revset() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); let bisection_script = test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); std::fs::write(&bisection_script, ["fail"].join("\0"))?; insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=none()", &bisector_path]), @" Search complete. To discard any revisions created during search, run: jj op restore f63ee16f9553 [EOF] ------- stderr ------- Error: Could not find the first bad revision. Was the input range empty? [EOF] [exit status: 1] "); Ok(()) } #[test] fn test_bisect_run() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); let bisection_script = test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); std::fs::write(&bisection_script, ["fail"].join("\0"))?; insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--trust-endpoints", &bisector_path]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is bad. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is bad. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first bad revision is: rlvkpnrz 7d980be7 a | a [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Working copy (@) now at: rsllmpnm 5f328bc5 (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ rsllmpnmslon 5f328bc5fde0 '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); // Try with legacy command argument std::fs::write(&bisection_script, ["fail"].join("\0"))?; // Testing only stderr to avoid a variable op id in the stdout. insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--trust-endpoints", "--command", &bisector_path]).success().stderr, @" Warning: `--command` is deprecated; use positional arguments instead: `jj bisect run --range=... -- $FAKE_BISECTOR_PATH` Working copy (@) now at: nkmrtpmo 1601f7b4 (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 2 files, modified 0 files, removed 0 files Working copy (@) now at: ruktrxxu fb9e625c (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ ruktrxxusqqp fb9e625c1023 '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); Ok(()) } #[test] // like test_bisect::test_bisect_nonlinear // bisecting over commits 0,1,2,3,4,5,6 with 5 being the first bad commit // this fails because 6 should also be bad! fn test_bisect_run_nonlinear_no_merge() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); // h // |\ // f g // | | // d e // | | // b c // |/ // a create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["a"]); create_commit(&work_dir, "d", &["b"]); create_commit(&work_dir, "e", &["c"]); create_commit(&work_dir, "f", &["d"]); create_commit(&work_dir, "g", &["e"]); create_commit(&work_dir, "h", &["f", "g"]); // rather than complicating fake_bisector, we try and --find-good insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=ancestors(parents(h))", "--find-good", "--", &bisector_path, "--require-file=f"]), @" Pre-bisection check: ensuring this revision is good: kmkuslsw 3548fddf f | f fake-bisector testing commit 3548fddfc5b69ba4c5b78a19c1cc6d39e52e5a22 Pre-bisection check: ensuring this revision is good: lylxulpl 97949f0f g | g fake-bisector testing commit 97949f0f52afedfc72ef44d63d21266bbfc42774 Cannot bisect: this revision was expected to be good, but was bad (exit status: 1) instead. Search complete. To discard any revisions created during search, run: jj op restore 7d0937f0feb3 [EOF] ------- stderr ------- Working copy (@) now at: xznxytkn 08be40de (empty) (no description set) Parent commit (@-) : kmkuslsw 3548fddf f | f Added 0 files, modified 0 files, removed 4 files Working copy (@) now at: smwtzssm fc3a931c (empty) (no description set) Parent commit (@-) : lylxulpl 97949f0f g | g Added 3 files, modified 0 files, removed 3 files Error: Bisection preconditions failed [EOF] [exit status: 1] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ smwtzssmuxzk fc3a931c8da8 '' files: │ ○ nkmrtpmomlro b47137c13576 'h' files: h ╭─┤ ○ │ lylxulplsnyw 97949f0f52af 'g' files: g ○ │ znkkpsqqskkl efcb3d331401 'e' files: e ○ │ royxmykxtrkr 991a7501d660 'c' files: c │ ○ kmkuslswpqwq 3548fddfc5b6 'f' files: f │ ○ vruxwmqvtpmx 01a5f35e756c 'd' files: d │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); Ok(()) } // like test_bisect_run_nonlinear_with_merge, but we include the merge commit. // that makes it okay for commit f to be the first bad one. #[test] fn test_bisect_run_nonlinear_with_merge() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); // h // |\ // f g // | | // d e // | | // b c // |/ // a create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["a"]); create_commit(&work_dir, "d", &["b"]); create_commit(&work_dir, "e", &["c"]); create_commit(&work_dir, "f", &["d"]); create_commit(&work_dir, "g", &["e"]); create_commit(&work_dir, "h", &["f", "g"]); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--find-good", "--", &bisector_path, "--require-file=f"]), @" Pre-bisection check: ensuring this revision is good: nkmrtpmo b47137c1 h | h fake-bisector testing commit b47137c135761c932a7d0c1619d6121868eb7df9 Pre-bisection check: ensuring this revision is bad: zzzzzzzz 00000000 (empty) (no description set) fake-bisector testing commit 0000000000000000000000000000000000000000 Bisecting: 7 revisions left to test after this (roughly 3 steps) Now evaluating: vruxwmqv 01a5f35e d | d fake-bisector testing commit 01a5f35e756cec7f8543120aeedcce0d086a2504 The revision is bad. Bisecting: 4 revisions left to test after this (roughly 3 steps) Now evaluating: znkkpsqq efcb3d33 e | e fake-bisector testing commit efcb3d33140196e8aa5157e4c865e9a4c513f8bb The revision is bad. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: kmkuslsw 3548fddf f | f fake-bisector testing commit 3548fddfc5b69ba4c5b78a19c1cc6d39e52e5a22 The revision is good. Search complete. To discard any revisions created during search, run: jj op restore 7d0937f0feb3 The first good revision is: kmkuslsw 3548fddf f | f [EOF] ------- stderr ------- Working copy (@) now at: xznxytkn 8d14f10f (empty) (no description set) Parent commit (@-) : nkmrtpmo b47137c1 h | h Working copy (@) now at: smwtzssm 71beb6f1 (empty) (no description set) Parent commit (@-) : zzzzzzzz 00000000 (empty) (no description set) Added 0 files, modified 0 files, removed 8 files Working copy (@) now at: zlusorwl 1576a092 (empty) (no description set) Parent commit (@-) : vruxwmqv 01a5f35e d | d Added 3 files, modified 0 files, removed 0 files Working copy (@) now at: ukzzzykq 05f4e27a (empty) (no description set) Parent commit (@-) : znkkpsqq efcb3d33 e | e Added 2 files, modified 0 files, removed 2 files Working copy (@) now at: lqoxyrsk 4967f850 (empty) (no description set) Parent commit (@-) : kmkuslsw 3548fddf f | f Added 3 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ lqoxyrskwpry 4967f85032d5 '' files: │ ○ nkmrtpmomlro b47137c13576 'h' files: h ╭─┤ │ ○ lylxulplsnyw 97949f0f52af 'g' files: g │ ○ znkkpsqqskkl efcb3d331401 'e' files: e │ ○ royxmykxtrkr 991a7501d660 'c' files: c ○ │ kmkuslswpqwq 3548fddfc5b6 'f' files: f ○ │ vruxwmqvtpmx 01a5f35e756c 'd' files: d ○ │ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); Ok(()) } #[test] fn test_bisect_run_find_first_good() { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--find-good", "--trust-endpoints", &bisector_path]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is good. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is good. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first good revision is: rlvkpnrz 7d980be7 a | a [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Working copy (@) now at: rsllmpnm 5f328bc5 (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ rsllmpnmslon 5f328bc5fde0 '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c │ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ├─╯ ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); } #[test] fn test_bisect_run_missing_bisector() { let test_env = TestEnvironment::default(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); let output = work_dir.run_jj([ "bisect", "run", "--range=..", "--trust-endpoints", "nonexistent", ]); if cfg!(unix) { insta::assert_snapshot!(output, @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Error: Failed to run evaluation command Caused by: No such file or directory (os error 2) [EOF] [exit status: 1] "); } else if cfg!(windows) { insta::assert_snapshot!(output, @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Error: Failed to run evaluation command Caused by: program not found [EOF] [exit status: 1] "); } } #[test] fn test_bisect_run_with_args() { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--find-good", "--trust-endpoints", "--", &bisector_path, "--require-file=c"]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is good. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is bad. Bisecting: 1 revisions left to test after this (roughly 1 steps) Now evaluating: zsuskuln 123b4d91 b | b fake-bisector testing commit 123b4d91f6e5e39bfed39bae3bacf9380dc79078 The revision is bad. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first good revision is: royxmykx dffaa0d4 c | c [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c Added 0 files, modified 0 files, removed 3 files Working copy (@) now at: rsllmpnm 5f328bc5 (empty) (no description set) Parent commit (@-) : rlvkpnrz 7d980be7 a | a Added 0 files, modified 0 files, removed 2 files Working copy (@) now at: zqsquwqt 042badd2 (empty) (no description set) Parent commit (@-) : zsuskuln 123b4d91 b | b Added 1 files, modified 0 files, removed 0 files [EOF] "); insta::assert_snapshot!(get_log_output(&work_dir), @" @ zqsquwqtrvts 042badd28c1d '' files: │ ○ kmkuslswpqwq 8b67af288466 'f' files: f │ ○ znkkpsqqskkl 62d30ded0e8f 'e' files: e │ ○ vruxwmqvtpmx 86be7a223919 'd' files: d │ ○ royxmykxtrkr dffaa0d4dacc 'c' files: c ├─╯ ○ zsuskulnrvyr 123b4d91f6e5 'b' files: b ○ rlvkpnrzqnoo 7d980be7a1d4 'a' files: a ◆ zzzzzzzzzzzz 000000000000 '' files: [EOF] "); } #[test] fn test_bisect_run_crash() -> TestResult { let mut test_env = TestEnvironment::default(); let bisector_path = fake_bisector_path(); let bisection_script = test_env.set_up_fake_bisector(); test_env.run_jj_in(".", ["git", "init", "repo"]).success(); let work_dir = test_env.work_dir("repo"); create_commit(&work_dir, "a", &[]); create_commit(&work_dir, "b", &["a"]); create_commit(&work_dir, "c", &["b"]); create_commit(&work_dir, "d", &["c"]); create_commit(&work_dir, "e", &["d"]); create_commit(&work_dir, "f", &["e"]); // bisector crash is equivalent to a failure std::fs::write(&bisection_script, ["crash"].join("\0"))?; insta::assert_snapshot!(work_dir.run_jj(["bisect", "run", "--range=..", "--trust-endpoints", &bisector_path]), @" Bisecting: 5 revisions left to test after this (roughly 3 steps) Now evaluating: royxmykx dffaa0d4 c | c fake-bisector testing commit dffaa0d4daccf6cee70bac3498fae3b3fd5d6b5b The revision is bad. Bisecting: 2 revisions left to test after this (roughly 2 steps) Now evaluating: rlvkpnrz 7d980be7 a | a fake-bisector testing commit 7d980be7a1d499e4d316ab4c01242885032f7eaf The revision is bad. Search complete. To discard any revisions created during search, run: jj op restore e953363a3d33 The first bad revision is: rlvkpnrz 7d980be7 a | a [EOF] ------- stderr ------- Working copy (@) now at: lylxulpl 68b3a16f (empty) (no description set) Parent commit (@-) : royxmykx dffaa0d4 c | c