on 89fcbb2 help sign in
bat/tests/integration_tests.rs
450 lines 8.1 kB history raw
1extern crate assert_cmd;
2extern crate escargot;
3#[macro_use]
4extern crate lazy_static;
6use assert_cmd::prelude::*;
7use escargot::CargoRun;
8use std::process::Command;
10lazy_static! {
11 static ref CARGO_RUN: CargoRun = escargot::CargoBuild::new()
12 .bin("bat")
13 .current_release()
14 .run()
15 .unwrap();
18fn bat_with_config() -> Command {
19 let mut cmd = CARGO_RUN.command();
20 cmd.current_dir("tests/examples");
21 cmd.env_remove("PAGER");
22 cmd.env_remove("BAT_PAGER");
23 cmd.env_remove("BAT_CONFIG_PATH");
24 cmd.env_remove("BAT_STYLE");
25 cmd.env_remove("BAT_THEME");
26 cmd.env_remove("BAT_TABS");
27 cmd
30fn bat() -> Command {
31 let mut cmd = bat_with_config();
32 cmd.arg("--no-config");
33 cmd
36#[test]
37fn basic() {
38 bat()
39 .arg("test.txt")
40 .assert()
41 .success()
42 .stdout("hello world\n")
43 .stderr("");
46#[test]
47fn stdin() {
48 bat()
49 .with_stdin()
50 .buffer("foo\nbar\n")
51 .assert()
52 .success()
53 .stdout("foo\nbar\n");
56#[test]
57fn concatenate() {
58 bat()
59 .arg("test.txt")
60 .arg("test.txt")
61 .assert()
62 .success()
63 .stdout("hello world\nhello world\n");
66#[test]
67fn concatenate_stdin() {
68 bat()
69 .arg("test.txt")
70 .arg("-")
71 .arg("test.txt")
72 .with_stdin()
73 .buffer("stdin\n")
74 .assert()
75 .success()
76 .stdout("hello world\nstdin\nhello world\n");
79#[test]
80fn concatenate_empty_first() {
81 bat()
82 .arg("empty.txt")
83 .arg("test.txt")
84 .assert()
85 .success()
86 .stdout("hello world\n");
89#[test]
90fn concatenate_empty_last() {
91 bat()
92 .arg("test.txt")
93 .arg("empty.txt")
94 .assert()
95 .success()
96 .stdout("hello world\n");
99#[test]
100fn concatenate_empty_both() {
101 bat()
102 .arg("empty.txt")
103 .arg("empty.txt")
104 .assert()
105 .success()
106 .stdout("");
109#[test]
110fn concatenate_empty_between() {
111 bat()
112 .arg("test.txt")
113 .arg("empty.txt")
114 .arg("test.txt")
115 .assert()
116 .success()
117 .stdout("hello world\nhello world\n");
120#[test]
121fn concatenate_empty_first_and_last() {
122 bat()
123 .arg("empty.txt")
124 .arg("test.txt")
125 .arg("empty.txt")
126 .assert()
127 .success()
128 .stdout("hello world\n");
131#[test]
132fn concatenate_single_line() {
133 bat()
134 .arg("single-line.txt")
135 .arg("single-line.txt")
136 .assert()
137 .success()
138 .stdout("Single LineSingle Line");
141#[test]
142fn concatenate_single_line_empty() {
143 bat()
144 .arg("single-line.txt")
145 .arg("empty.txt")
146 .arg("single-line.txt")
147 .assert()
148 .success()
149 .stdout("Single LineSingle Line");
152#[test]
153fn line_numbers() {
154 bat()
155 .arg("multiline.txt")
156 .arg("--style=numbers")
157 .arg("--decorations=always")
158 .assert()
159 .success()
160 .stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
163#[test]
164fn line_range_2_3() {
165 bat()
166 .arg("multiline.txt")
167 .arg("--line-range=2:3")
168 .assert()
169 .success()
170 .stdout("line 2\nline 3\n");
173#[test]
174fn line_range_first_two() {
175 bat()
176 .arg("multiline.txt")
177 .arg("--line-range=:2")
178 .assert()
179 .success()
180 .stdout("line 1\nline 2\n");
183#[test]
184fn line_range_last_3() {
185 bat()
186 .arg("multiline.txt")
187 .arg("--line-range=2:")
188 .assert()
189 .success()
190 .stdout("line 2\nline 3\nline 4\n");
193#[test]
194fn line_range_multiple() {
195 bat()
196 .arg("multiline.txt")
197 .arg("--line-range=1:2")
198 .arg("--line-range=4:4")
199 .assert()
200 .success()
201 .stdout("line 1\nline 2\nline 4\n");
204#[test]
205fn tabs_numbers() {
206 bat()
207 .arg("tabs.txt")
208 .arg("--tabs=4")
209 .arg("--style=numbers")
210 .arg("--decorations=always")
211 .assert()
212 .success()
213 .stdout(
214 " 1 1 2 3 4
215 2 1 ?
216 3 22 ?
217 4 333 ?
218 5 4444 ?
219 6 55555 ?
220 7 666666 ?
221 8 7777777 ?
222 9 88888888 ?
223",
224 );
227#[test]
228fn tabs_passthrough_wrapped() {
229 bat()
230 .arg("tabs.txt")
231 .arg("--tabs=0")
232 .arg("--style=plain")
233 .arg("--decorations=always")
234 .assert()
235 .success()
236 .stdout(
237 " 1 2 3 4
2381 ?
23922 ?
240333 ?
2414444 ?
24255555 ?
243666666 ?
2447777777 ?
24588888888 ?
246",
247 );
250#[test]
251fn tabs_4_wrapped() {
252 bat()
253 .arg("tabs.txt")
254 .arg("--tabs=4")
255 .arg("--style=plain")
256 .arg("--decorations=always")
257 .assert()
258 .success()
259 .stdout(
260 " 1 2 3 4
2611 ?
26222 ?
263333 ?
2644444 ?
26555555 ?
266666666 ?
2677777777 ?
26888888888 ?
269",
270 );
273#[test]
274fn tabs_8_wrapped() {
275 bat()
276 .arg("tabs.txt")
277 .arg("--tabs=8")
278 .arg("--style=plain")
279 .arg("--decorations=always")
280 .assert()
281 .success()
282 .stdout(
283 " 1 2 3 4
2841 ?
28522 ?
286333 ?
2874444 ?
28855555 ?
289666666 ?
2907777777 ?
29188888888 ?
292",
293 );
296#[test]
297fn tabs_passthrough() {
298 bat()
299 .arg("tabs.txt")
300 .arg("--tabs=0")
301 .arg("--style=plain")
302 .arg("--decorations=always")
303 .assert()
304 .success()
305 .stdout(
306 " 1 2 3 4
3071 ?
30822 ?
309333 ?
3104444 ?
31155555 ?
312666666 ?
3137777777 ?
31488888888 ?
315",
316 );
319#[test]
320fn tabs_4() {
321 bat()
322 .arg("tabs.txt")
323 .arg("--tabs=4")
324 .arg("--style=plain")
325 .arg("--decorations=always")
326 .assert()
327 .success()
328 .stdout(
329 " 1 2 3 4
3301 ?
33122 ?
332333 ?
3334444 ?
33455555 ?
335666666 ?
3367777777 ?
33788888888 ?
338",
339 );
342#[test]
343fn tabs_8() {
344 bat()
345 .arg("tabs.txt")
346 .arg("--tabs=8")
347 .arg("--style=plain")
348 .arg("--decorations=always")
349 .assert()
350 .success()
351 .stdout(
352 " 1 2 3 4
3531 ?
35422 ?
355333 ?
3564444 ?
35755555 ?
358666666 ?
3597777777 ?
36088888888 ?
361",
362 );
365#[test]
366fn fail_non_existing() {
367 bat().arg("non-existing-file").assert().failure();
370#[test]
371fn fail_directory() {
372 bat().arg("sub_directory").assert().failure();
375#[test]
376fn do_not_exit_directory() {
377 bat()
378 .arg("sub_directory")
379 .arg("test.txt")
380 .assert()
381 .stdout("hello world\n")
382 .failure();
385#[test]
386fn pager_basic() {
387 bat()
388 .env("PAGER", "echo pager-output")
389 .arg("--paging=always")
390 .arg("test.txt")
391 .assert()
392 .success()
393 .stdout("pager-output\n");
396#[test]
397fn pager_overwrite() {
398 bat()
399 .env("PAGER", "echo other-pager")
400 .env("BAT_PAGER", "echo pager-output")
401 .arg("--paging=always")
402 .arg("test.txt")
403 .assert()
404 .success()
405 .stdout("pager-output\n");
408#[test]
409fn pager_disable() {
410 bat()
411 .env("PAGER", "echo other-pager")
412 .env("BAT_PAGER", "")
413 .arg("--paging=always")
414 .arg("test.txt")
415 .assert()
416 .success()
417 .stdout("hello world\n");
420#[test]
421fn config_location_test() {
422 bat_with_config()
423 .env("BAT_CONFIG_PATH", "bat.conf")
424 .arg("--config-file")
425 .assert()
426 .success()
427 .stdout("bat.conf\n");
430#[test]
431fn config_read_arguments_from_file() {
432 bat_with_config()
433 .env("BAT_CONFIG_PATH", "bat.conf")
434 .arg("test.txt")
435 .assert()
436 .success()
437 .stdout("dummy-pager-from-config\n");
440#[test]
441fn utf16() {
442 // The output will be converted to UTF-8 with a leading UTF-8 BOM
443 bat()
444 .arg("--plain")
445 .arg("--decorations=always")
446 .arg("test_UTF-16LE.txt")
447 .assert()
448 .success()
449 .stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());