just playing with tangled
at ig/vimdiffwarn 130 lines 3.7 kB view raw
1// Copyright 2022 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 15use crate::common::TestEnvironment; 16 17#[test] 18fn test_show() { 19 let test_env = TestEnvironment::default(); 20 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 21 let work_dir = test_env.work_dir("repo"); 22 23 work_dir.write_file("file1", "a\n"); 24 work_dir.run_jj(["new"]).success(); 25 work_dir.write_file("file1", "b\n"); 26 work_dir.create_dir("dir"); 27 work_dir.write_file("dir/file2", "c\n"); 28 29 // Can print the contents of a file in a commit 30 let output = work_dir.run_jj(["file", "show", "file1", "-r", "@-"]); 31 insta::assert_snapshot!(output, @r" 32 a 33 [EOF] 34 "); 35 36 // Defaults to printing the working-copy version 37 let output = work_dir.run_jj(["file", "show", "file1"]); 38 insta::assert_snapshot!(output, @r" 39 b 40 [EOF] 41 "); 42 43 // Can print a file in a subdirectory 44 let subdir_file = if cfg!(unix) { 45 "dir/file2" 46 } else { 47 "dir\\file2" 48 }; 49 let output = work_dir.run_jj(["file", "show", subdir_file]); 50 insta::assert_snapshot!(output, @r" 51 c 52 [EOF] 53 "); 54 55 // Error if the path doesn't exist 56 let output = work_dir.run_jj(["file", "show", "nonexistent"]); 57 insta::assert_snapshot!(output, @r" 58 ------- stderr ------- 59 Error: No such path: nonexistent 60 [EOF] 61 [exit status: 1] 62 "); 63 64 // Can print files under the specified directory 65 let output = work_dir.run_jj(["file", "show", "dir"]); 66 insta::assert_snapshot!(output, @r" 67 c 68 [EOF] 69 "); 70 71 // Can print multiple files 72 let output = work_dir.run_jj(["file", "show", "."]); 73 insta::assert_snapshot!(output, @r" 74 c 75 b 76 [EOF] 77 "); 78 79 // Unmatched paths should generate warnings 80 let output = work_dir.run_jj(["file", "show", "file1", "non-existent"]); 81 insta::assert_snapshot!(output, @r" 82 b 83 [EOF] 84 ------- stderr ------- 85 Warning: No matching entries for paths: non-existent 86 [EOF] 87 "); 88 89 // Can print a conflict 90 work_dir.run_jj(["new"]).success(); 91 work_dir.write_file("file1", "c\n"); 92 work_dir 93 .run_jj(["rebase", "-r", "@", "-d", "@--"]) 94 .success(); 95 let output = work_dir.run_jj(["file", "show", "file1"]); 96 insta::assert_snapshot!(output, @r" 97 <<<<<<< Conflict 1 of 1 98 %%%%%%% Changes from base to side #1 99 -b 100 +a 101 +++++++ Contents of side #2 102 c 103 >>>>>>> Conflict 1 of 1 ends 104 [EOF] 105 "); 106} 107 108#[cfg(unix)] 109#[test] 110fn test_show_symlink() { 111 let test_env = TestEnvironment::default(); 112 test_env.run_jj_in(".", ["git", "init", "repo"]).success(); 113 let work_dir = test_env.work_dir("repo"); 114 115 work_dir.write_file("file1", "a\n"); 116 work_dir.create_dir("dir"); 117 work_dir.write_file("dir/file2", "c\n"); 118 std::os::unix::fs::symlink("symlink1_target", work_dir.root().join("symlink1")).unwrap(); 119 120 // Can print multiple files 121 let output = work_dir.run_jj(["file", "show", "."]); 122 insta::assert_snapshot!(output, @r" 123 c 124 a 125 [EOF] 126 ------- stderr ------- 127 Warning: Path 'symlink1' exists but is not a file 128 [EOF] 129 "); 130}