on e04bccd help sign in
bat/tests/integration_tests.rs
365 lines 6.4 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 line_numbers() {
81 bat()
82 .arg("multiline.txt")
83 .arg("--style=numbers")
84 .arg("--decorations=always")
85 .assert()
86 .success()
87 .stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
90#[test]
91fn line_range_2_3() {
92 bat()
93 .arg("multiline.txt")
94 .arg("--line-range=2:3")
95 .assert()
96 .success()
97 .stdout("line 2\nline 3\n");
100#[test]
101fn line_range_first_two() {
102 bat()
103 .arg("multiline.txt")
104 .arg("--line-range=:2")
105 .assert()
106 .success()
107 .stdout("line 1\nline 2\n");
110#[test]
111fn line_range_last_3() {
112 bat()
113 .arg("multiline.txt")
114 .arg("--line-range=2:")
115 .assert()
116 .success()
117 .stdout("line 2\nline 3\nline 4\n");
120#[test]
121fn line_range_multiple() {
122 bat()
123 .arg("multiline.txt")
124 .arg("--line-range=1:2")
125 .arg("--line-range=4:4")
126 .assert()
127 .success()
128 .stdout("line 1\nline 2\nline 4\n");
131#[test]
132fn tabs_numbers() {
133 bat()
134 .arg("tabs.txt")
135 .arg("--tabs=4")
136 .arg("--style=numbers")
137 .arg("--decorations=always")
138 .assert()
139 .success()
140 .stdout(
141 " 1 1 2 3 4
142 2 1 ?
143 3 22 ?
144 4 333 ?
145 5 4444 ?
146 6 55555 ?
147 7 666666 ?
148 8 7777777 ?
149 9 88888888 ?
150",
151 );
154#[test]
155fn tabs_passthrough_wrapped() {
156 bat()
157 .arg("tabs.txt")
158 .arg("--tabs=0")
159 .arg("--style=plain")
160 .arg("--decorations=always")
161 .assert()
162 .success()
163 .stdout(
164 " 1 2 3 4
1651 ?
16622 ?
167333 ?
1684444 ?
16955555 ?
170666666 ?
1717777777 ?
17288888888 ?
173",
174 );
177#[test]
178fn tabs_4_wrapped() {
179 bat()
180 .arg("tabs.txt")
181 .arg("--tabs=4")
182 .arg("--style=plain")
183 .arg("--decorations=always")
184 .assert()
185 .success()
186 .stdout(
187 " 1 2 3 4
1881 ?
18922 ?
190333 ?
1914444 ?
19255555 ?
193666666 ?
1947777777 ?
19588888888 ?
196",
197 );
200#[test]
201fn tabs_8_wrapped() {
202 bat()
203 .arg("tabs.txt")
204 .arg("--tabs=8")
205 .arg("--style=plain")
206 .arg("--decorations=always")
207 .assert()
208 .success()
209 .stdout(
210 " 1 2 3 4
2111 ?
21222 ?
213333 ?
2144444 ?
21555555 ?
216666666 ?
2177777777 ?
21888888888 ?
219",
220 );
223#[test]
224fn tabs_passthrough() {
225 bat()
226 .arg("tabs.txt")
227 .arg("--tabs=0")
228 .arg("--style=plain")
229 .arg("--decorations=always")
230 .assert()
231 .success()
232 .stdout(
233 " 1 2 3 4
2341 ?
23522 ?
236333 ?
2374444 ?
23855555 ?
239666666 ?
2407777777 ?
24188888888 ?
242",
243 );
246#[test]
247fn tabs_4() {
248 bat()
249 .arg("tabs.txt")
250 .arg("--tabs=4")
251 .arg("--style=plain")
252 .arg("--decorations=always")
253 .assert()
254 .success()
255 .stdout(
256 " 1 2 3 4
2571 ?
25822 ?
259333 ?
2604444 ?
26155555 ?
262666666 ?
2637777777 ?
26488888888 ?
265",
266 );
269#[test]
270fn tabs_8() {
271 bat()
272 .arg("tabs.txt")
273 .arg("--tabs=8")
274 .arg("--style=plain")
275 .arg("--decorations=always")
276 .assert()
277 .success()
278 .stdout(
279 " 1 2 3 4
2801 ?
28122 ?
282333 ?
2834444 ?
28455555 ?
285666666 ?
2867777777 ?
28788888888 ?
288",
289 );
292#[test]
293fn fail_non_existing() {
294 bat().arg("non-existing-file").assert().failure();
297#[test]
298fn fail_directory() {
299 bat().arg("sub_directory").assert().failure();
302#[test]
303fn do_not_exit_directory() {
304 bat()
305 .arg("sub_directory")
306 .arg("test.txt")
307 .assert()
308 .stdout("hello world\n")
309 .failure();
312#[test]
313fn pager_basic() {
314 bat()
315 .env("PAGER", "echo pager-output")
316 .arg("--paging=always")
317 .arg("test.txt")
318 .assert()
319 .success()
320 .stdout("pager-output\n");
323#[test]
324fn pager_overwrite() {
325 bat()
326 .env("PAGER", "echo other-pager")
327 .env("BAT_PAGER", "echo pager-output")
328 .arg("--paging=always")
329 .arg("test.txt")
330 .assert()
331 .success()
332 .stdout("pager-output\n");
335#[test]
336fn pager_disable() {
337 bat()
338 .env("PAGER", "echo other-pager")
339 .env("BAT_PAGER", "")
340 .arg("--paging=always")
341 .arg("test.txt")
342 .assert()
343 .success()
344 .stdout("hello world\n");
347#[test]
348fn config_location_test() {
349 bat_with_config()
350 .env("BAT_CONFIG_PATH", "bat.conf")
351 .arg("--config-file")
352 .assert()
353 .success()
354 .stdout("bat.conf\n");
357#[test]
358fn config_read_arguments_from_file() {
359 bat_with_config()
360 .env("BAT_CONFIG_PATH", "bat.conf")
361 .arg("test.txt")
362 .assert()
363 .success()
364 .stdout("dummy-pager-from-config\n");