Debian Codegraph @

src/tests/integration_test_utils.rs

raw symbols SCIP
1 #![cfg(test)]
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
4 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#;
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#};
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#;
7
8 use bytelinesrust-analyzer cargo bytelines 2.5.0 crate/::ByteLinesrust-analyzer cargo bytelines 2.5.0 std/ByteLines#;
9 use itertoolsrust-analyzer cargo itertools 0.14.0 crate/::Itertoolsrust-analyzer cargo itertools 0.14.0 Itertools#;
10
11 use craterust-analyzer cargo git-delta 0.19.2 crate/::ansirust-analyzer cargo git-delta 0.19.2 ansi/;
12 use craterust-analyzer cargo git-delta 0.19.2 crate/::clirust-analyzer cargo git-delta 0.19.2 cli/;
13 use craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/;
14 use craterust-analyzer cargo git-delta 0.19.2 crate/::deltarust-analyzer cargo git-delta 0.19.2 delta/::deltarust-analyzer cargo git-delta 0.19.2 delta/delta().;
15 use craterust-analyzer cargo git-delta 0.19.2 crate/::envrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#;
16 use craterust-analyzer cargo git-delta 0.19.2 crate/::git_configrust-analyzer cargo git-delta 0.19.2 git_config/::GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#;
17 use craterust-analyzer cargo git-delta 0.19.2 crate/::testsrust-analyzer cargo git-delta 0.19.2 tests/::test_utilsrust-analyzer cargo git-delta 0.19.2 tests/test_utils/;
18 use craterust-analyzer cargo git-delta 0.19.2 crate/::utilsrust-analyzer cargo git-delta 0.19.2 utils/::processrust-analyzer cargo git-delta 0.19.2 utils/process/::testsrust-analyzer cargo git-delta 0.19.2 utils/process/tests/::FakeParentArgsrust-analyzer cargo git-delta 0.19.2 utils/process/tests/FakeParentArgs#;
19
20 pub fn make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
21 args: &[&str],
22 git_config_contents: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]>,
23 git_config_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
24 ) -> clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt# {
25 _make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/_make_options_from_args_and_git_config().(
26 DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::defaultrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv][Default]default().(),
27 args,
28 git_config_contents,
29 git_config_path,
30 false,
31 )
32 }
33
34 pub fn make_options_from_args_and_git_config_with_custom_envrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config_with_custom_env().(
35 env: DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#,
36 args: &[&str],
37 git_config_contents: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]>,
38 git_config_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
39 ) -> clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt# {
40 _make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/_make_options_from_args_and_git_config().(env, args, git_config_contents, git_config_path, false)
41 }
42
43 pub fn make_options_from_args_and_git_config_honoring_env_var_with_custom_envrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config_honoring_env_var_with_custom_env().(
44 env: DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#,
45 args: &[&str],
46 git_config_contents: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]>,
47 git_config_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
48 ) -> clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt# {
49 _make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/_make_options_from_args_and_git_config().(env, args, git_config_contents, git_config_path, true)
50 }
51
52 fn _make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/_make_options_from_args_and_git_config().(
53 env: DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#,
54 args: &[&str],
55 git_config_contents: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]>,
56 git_config_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
57 honor_env_var: bool,
58 ) -> clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt# {
59 let mut args: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<&str> = itertoolsrust-analyzer cargo itertools 0.14.0 crate/::chainrust-analyzer cargo itertools 0.14.0 free/chain().(&["/dev/null", "/dev/null"], args)
60 .copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().()
61 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
62 let git_config = match (git_config_contents, git_config_path) {
63 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(contents), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(path)) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(make_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_git_config().(&env, contents, path, honor_env_var)),
64 _ => {
65 args.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().("--no-gitconfig");
66 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
67 }
68 };
69 clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt#::from_iter_and_git_configrust-analyzer cargo git-delta 0.19.2 cli/impl#[Opt]from_iter_and_git_config().(&env, args, git_config)
70 }
71
72 pub fn make_options_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args().(args: &[&str]) -> clirust-analyzer cargo git-delta 0.19.2 cli/::Optrust-analyzer cargo git-delta 0.19.2 cli/Opt# {
73 make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(args, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
74 }
75
76 #[allow(dead_code)]
77 pub fn make_config_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args_and_git_config().(
78 args: &[&str],
79 git_config_contents: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&[u8]>,
80 git_config_path: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>,
81 ) -> configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config# {
82 configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#::fromrust-analyzer cargo git-delta 0.19.2 config/impl#[Config][`From<cli::Opt>`]from().(make_options_from_args_and_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args_and_git_config().(
83 args,
84 git_config_contents,
85 git_config_path,
86 ))
87 }
88
89 pub fn make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(args: &[&str]) -> configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config# {
90 configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#::fromrust-analyzer cargo git-delta 0.19.2 config/impl#[Config][`From<cli::Opt>`]from().(make_options_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_options_from_args().(args))
91 }
92
93 pub fn make_git_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_git_config().(
94 env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#,
95 contents: &[u8],
96 path: &str,
97 honor_env_var: bool,
98 ) -> GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig# {
99 let path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().(path);
100 let mut file = Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::createrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]create().(path).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
101 file.write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(contents).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
102 GitConfigrust-analyzer cargo git-delta 0.19.2 git_config/GitConfig#::from_pathrust-analyzer cargo git-delta 0.19.2 git_config/impl#[GitConfig]from_path().(env, path, honor_env_var)
103 }
104
105 pub fn get_line_of_code_from_deltarust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/get_line_of_code_from_delta().(
106 input: &str,
107 line_number: usize,
108 expected_text: &str,
109 config: &configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#,
110 ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
111 let output = run_deltarust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/run_delta().(input, config);
112 let line_of_code = output.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().nthrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#nth().(line_number).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
113 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(ansirust-analyzer cargo git-delta 0.19.2 ansi/::strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().(line_of_code) == expected_text);
114 line_of_code.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
115 }
116
117 // Given an `expected` block as a raw string like: `r#"
118 // #indent_mark [optional]
119 // line1"#;` // line 2 etc.
120 // ignore the first newline and compare the following `lines()` to those produced
121 // by `have`, `skip`-ping the first few. The leading spaces of the first line
122 // to indicate the last line in the list). The leading spaces of the first line
123 // are stripped from every following line (and verified), unless the first line
124 // marks the indentation level with `#indent_mark`.
125 pub fn assert_lines_match_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match_after_skip().(skip: usize, expected: &str, have: &str) {
126 let mut exp = expected.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().();
127 let mut line1 = exp.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
128 let allow_partial = line1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."#partial";
129 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
130 allow_partial || line1.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().(),
131 "first line must be empty or \"#partial\""
132 );
133 line1 = exp.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
134 let indentation = line1.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().' ').unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
135 let ignore_indent = &line1[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().indentation..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."#indent_mark";
136 if ignore_indent {
137 let _indent_mark = exp.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().();
138 }
139
140 let mut it = have.linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(skip);
141
142 for (i, expected) in exp.enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() {
143 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ignore_indent {
144 let next_indentation = expected.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(|c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().' ').unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
145 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
146 indentation == next_indentation,
147 "The expected block has mixed indentation (use #indent_mark if that is on purpose)"
148 );
149 }
150 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
151 &expected[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().indentation..]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().,
152 it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(),
153 "on line {} of input:\n{}",
154 i +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). 1,
155 delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(have),
156 );
157 }
158 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().allow_partial {
159 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/skip/impl#[`Skip<I>`][Iterator]next().(), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, "more input than expected");
160 }
161 }
162
163 pub fn assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected: &str, have: &str) {
164 assert_lines_match_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match_after_skip().(0, expected, have)
165 }
166
167 pub fn delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(txt: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
168 let top = "▼".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(100);
169 let btm = "▲".repeatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]repeat().(100);
170 let nl = "\n";
171 top rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().nl rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().txt rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().+rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Add<&str>`]add().nl rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#add().&btm
172 }
173
174 pub struct DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#<'a> {
175 configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#config.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#>,
176 calling_processrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#calling_process.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
177 explain_ansi_rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#explain_ansi_.: bool,
178 }
179
180 impl<'a> DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#<'a> {
181 pub fn with_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_args().(args: &[&str]) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`] {
182 Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`] {
183 configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#config.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(make_config_from_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/make_config_from_args().(args)),
184 calling_processrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#calling_process.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
185 explain_ansi_rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#explain_ansi_.: false,
186 }
187 }
188
189 pub fn with_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_config().(config: &'a configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`] {
190 Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`] {
191 configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#config.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(config),
192 calling_processrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#calling_process.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
193 explain_ansi_rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#explain_ansi_.: false,
194 }
195 }
196
197 pub fn set_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]set_config().<F>(mut self, f: F) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]
198 where
199 F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&mut configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#),
200 {
201 let mut owned_config = self.configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#config..into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().();
202 f(&mut owned_config);
203 self.configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#config. = Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(owned_config);
204 self
205 }
206
207 pub fn with_calling_processrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_calling_process().(mut self, command: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`] {
208 self.calling_processrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#calling_process. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(command.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().());
209 self
210 }
211
212 pub fn explain_ansirust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]explain_ansi().(mut self) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`] {
213 self.explain_ansi_rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#explain_ansi_. = true;
214 self
215 }
216
217 pub fn with_inputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_input().(&self, input: &str) -> DeltaTestOutputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput# {
218 let _args = FakeParentArgsrust-analyzer cargo git-delta 0.19.2 utils/process/tests/FakeParentArgs#::for_scoperust-analyzer cargo git-delta 0.19.2 utils/process/tests/impl#[FakeParentArgs]for_scope().(self.calling_processrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#calling_process..as_derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_deref().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(""));
219 let raw = run_deltarust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/run_delta().(input, &self.configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#config.);
220 let cooked = if self.explain_ansi_rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#explain_ansi_. {
221 ansirust-analyzer cargo git-delta 0.19.2 ansi/::explain_ansirust-analyzer cargo git-delta 0.19.2 ansi/explain_ansi().(&raw, false)
222 } else {
223 ansirust-analyzer cargo git-delta 0.19.2 ansi/::strip_ansi_codesrust-analyzer cargo git-delta 0.19.2 ansi/strip_ansi_codes().(&raw)
224 };
225
226 DeltaTestOutputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput# {
227 raw_outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#raw_output.: raw,
228 outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output.: cooked,
229 }
230 }
231 }
232
233 pub struct DeltaTestOutputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput# {
234 pub raw_outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#raw_output.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
235 pub outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
236 }
237
238 impl DeltaTestOutputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput# {
239 /// Print output, either without ANSI escape sequences or, if explain_ansi() has been called,
240 /// with ASCII explanation of ANSI escape sequences.
241 #[allow(unused)]
242 pub fn inspectrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]inspect().(self) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
243 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{}", delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(&self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output.));
244 self
245 }
246
247 /// Print raw output, with any ANSI escape sequences.
248 #[allow(unused)]
249 pub fn inspect_rawrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]inspect_raw().(self) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
250 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("{}", delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(&self.raw_outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#raw_output.));
251 self
252 }
253
254 pub fn expect_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_after_skip().(self, skip: usize, expected: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
255 assert_lines_match_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match_after_skip().(skip, expected, &self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output.);
256 self
257 }
258
259 pub fn expectrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect().(self, expected: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
260 self.expect_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_after_skip().(0, expected)
261 }
262
263 pub fn expect_after_headerrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_after_header().(self, expected: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
264 self.expect_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_after_skip().(craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/::HEADER_LENrust-analyzer cargo git-delta 0.19.2 config/HEADER_LEN., expected)
265 }
266
267 pub fn skip_headerrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]skip_header().(self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
268 self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output..linesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]lines().().skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(configrust-analyzer cargo git-delta 0.19.2 config/::HEADER_LENrust-analyzer cargo git-delta 0.19.2 config/HEADER_LEN.).joinrust-analyzer cargo itertools 0.14.0 Itertools#join().("\n")
269 }
270
271 pub fn expect_containsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_contains().(self, expected: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
272 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
273 self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(expected),
274 "Output does not contain \"{}\":\n{}\n",
275 expected,
276 delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(&self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output.)
277 );
278 self
279 }
280
281 pub fn expect_raw_containsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_raw_contains().(self, expected: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
282 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
283 self.raw_outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#raw_output..containsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]contains().(expected),
284 "Raw output does not contain \"{}\":\n{}\n",
285 expected,
286 delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(&self.raw_outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#raw_output.)
287 );
288 self
289 }
290
291 pub fn expect_contains_oncerust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_contains_once().(self, expected: &str) -> Selfrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput] {
292 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(
293 test_utilsrust-analyzer cargo git-delta 0.19.2 tests/test_utils/::contains_oncerust-analyzer cargo git-delta 0.19.2 tests/test_utils/contains_once().(&self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output., expected),
294 "Output does not contain \"{}\" exactly once:\n{}\n",
295 expected,
296 delineated_stringrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/delineated_string().(&self.outputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTestOutput#output.)
297 );
298 self
299 }
300 }
301
302 pub fn run_deltarust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/run_delta().(input: &str, config: &configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
303 let mut writer: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().();
304
305 deltarust-analyzer cargo git-delta 0.19.2 delta/delta().(
306 ByteLinesrust-analyzer cargo bytelines 2.5.0 std/ByteLines#::newrust-analyzer cargo bytelines 2.5.0 std/impl#[`ByteLines<B>`]new().(BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(input.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().())),
307 &mut writer,
308 config,
309 )
310 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
311 Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(writer).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()
312 }
313
314 pub mod testsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/ {
315 use superrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/::*;
316
317 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
318 fn test_lines_match_okrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/test_lines_match_ok().() {
319 let expected = r#"
320 one
321 two
322 three"#;
323 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "one\ntwo\nthree");
324
325 let expected = r#"
326 #indent_mark
327 one
328 2
329 three"#;
330 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "one\n 2\nthree");
331
332 let expected = r#"
333 #indent_mark
334 1
335 2
336 3"#;
337 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, " 1 \n 2 \n 3");
338
339 let expected = r#"
340 #indent_mark
341 1
342 ignored! 2
343 3"#;
344 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, " 1 \n 2 \n 3");
345 let expected = "\none\ntwo\nthree";
346 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "one\ntwo\nthree");
347 }
348
349 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
350 #[should_panic]
351 fn test_lines_match_no_nlrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/test_lines_match_no_nl().() {
352 let expected = r#"bad
353 lines"#;
354 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "bad\nlines");
355 }
356
357 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
358 #[should_panic]
359 fn test_lines_match_iter_not_consumedrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/test_lines_match_iter_not_consumed().() {
360 let expected = r#"
361 one
362 two
363 three"#;
364 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "one\ntwo\nthree\nFOUR");
365 }
366
367 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
368 #[should_panic]
369 fn test_lines_match_no_indent_mark_1rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/test_lines_match_no_indent_mark_1().() {
370 let expected = r#"
371 ok
372 wrong_indent
373 "#;
374 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "ok");
375 }
376
377 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
378 #[should_panic]
379 fn test_lines_match_no_indent_mark_2rust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/test_lines_match_no_indent_mark_2().() {
380 let expected = r#"
381 ok
382 wrong_indent
383 "#;
384 assert_lines_matchrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/assert_lines_match().(expected, "ok");
385 }
386
387 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
388 fn test_delta_testrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/tests/test_delta_test().() {
389 let input = "@@ -1,1 +1,1 @@ fn foo() {\n-1\n+2\n";
390 DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#::with_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_args().(&["--raw"])
391 .set_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]set_config().(|c| c.pagerrust-analyzer cargo git-delta 0.19.2 config/Config#pager. = Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
392 .set_configrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]set_config().(|c| c.line_numbersrust-analyzer cargo git-delta 0.19.2 config/Config#line_numbers. = true)
393 .with_inputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_input().(input)
394 .expectrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect().(
395 r#"
396 #indent_mark
397 @@ -1,1 +1,1 @@ fn foo() {
398 1 ⋮ │-1
399 ⋮ 1 │+2"#,
400 );
401
402 DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#::with_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_args().(&[])
403 .with_inputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_input().(input)
404 .expect_after_skiprust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect_after_skip().(
405 4,
406 r#"
407 1
408 2"#,
409 );
410
411 DeltaTestrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/DeltaTest#::with_argsrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_args().(&["--raw"])
412 .explain_ansirust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]explain_ansi().()
413 .with_inputrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[`DeltaTest<'a>`]with_input().(input)
414 .expectrust-analyzer cargo git-delta 0.19.2 tests/integration_test_utils/impl#[DeltaTestOutput]expect().(
415 "\n\
416 (normal)@@ -1,1 +1,1 @@ fn foo() {\n\
417 (red)-1(normal)\n\
418 (green)+2(normal)",
419 );
420 }
421 }