1use assert_cmd::Command;
3use std::str::from_utf8;
5const EXAMPLES_DIR: &str = "tests/examples";
7fn bat_with_config() -> Command {
8 let mut cmd = Command::cargo_bin("bat").unwrap();
9 cmd.current_dir("tests/examples");
10 cmd.env_remove("PAGER");
11 cmd.env_remove("BAT_PAGER");
12 cmd.env_remove("BAT_CONFIG_PATH");
13 cmd.env_remove("BAT_STYLE");
14 cmd.env_remove("BAT_THEME");
15 cmd.env_remove("BAT_TABS");
20 let mut cmd = bat_with_config();
21 cmd.arg("--no-config");
31 .stdout("hello world\n")
38 .write_stdin("foo\nbar\n")
41 .stdout("foo\nbar\n");
51 .stdout("hello world\nhello world\n");
55fn concatenate_stdin() {
60 .write_stdin("stdin\n")
63 .stdout("hello world\nstdin\nhello world\n");
67fn concatenate_empty_first() {
73 .stdout("hello world\n");
77fn concatenate_empty_last() {
83 .stdout("hello world\n");
87fn concatenate_empty_both() {
97fn concatenate_empty_between() {
104 .stdout("hello world\nhello world\n");
108fn concatenate_empty_first_and_last() {
115 .stdout("hello world\n");
119fn concatenate_single_line() {
121 .arg("single-line.txt")
122 .arg("single-line.txt")
125 .stdout("Single LineSingle Line");
129fn concatenate_single_line_empty() {
131 .arg("single-line.txt")
133 .arg("single-line.txt")
136 .stdout("Single LineSingle Line");
142 .arg("multiline.txt")
143 .arg("--style=numbers")
144 .arg("--decorations=always")
147 .stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
153 .arg("multiline.txt")
154 .arg("--line-range=2:3")
157 .stdout("line 2\nline 3\n");
161fn line_range_first_two() {
163 .arg("multiline.txt")
164 .arg("--line-range=:2")
167 .stdout("line 1\nline 2\n");
171fn line_range_last_3() {
173 .arg("multiline.txt")
174 .arg("--line-range=2:")
177 .stdout("line 2\nline 3\nline 4\n");
181fn line_range_multiple() {
183 .arg("multiline.txt")
184 .arg("--line-range=1:2")
185 .arg("--line-range=4:4")
188 .stdout("line 1\nline 2\nline 4\n");
196 .arg("--style=numbers")
197 .arg("--decorations=always")
215fn tabs_passthrough_wrapped() {
219 .arg("--style=plain")
220 .arg("--decorations=always")
242 .arg("--style=plain")
243 .arg("--decorations=always")
265 .arg("--style=plain")
266 .arg("--decorations=always")
284fn tabs_passthrough() {
288 .arg("--style=plain")
289 .arg("--decorations=always")
311 .arg("--style=plain")
312 .arg("--decorations=always")
334 .arg("--style=plain")
335 .arg("--decorations=always")
353fn fail_non_existing() {
354 bat().arg("non-existing-file").assert().failure();
359 bat().arg("sub_directory").assert().failure();
363fn do_not_exit_directory() {
365 .arg("sub_directory")
368 .stdout("hello world\n")
375 .env("PAGER", "echo pager-output")
376 .arg("--paging=always")
380 .stdout("pager-output\n");
384fn pager_overwrite() {
386 .env("PAGER", "echo other-pager")
387 .env("BAT_PAGER", "echo pager-output")
388 .arg("--paging=always")
392 .stdout("pager-output\n");
398 .env("PAGER", "echo other-pager")
399 .env("BAT_PAGER", "")
400 .arg("--paging=always")
404 .stdout("hello world\n");
408fn config_location_test() {
410 .env("BAT_CONFIG_PATH", "bat.conf")
411 .arg("--config-file")
414 .stdout("bat.conf\n");
418fn config_read_arguments_from_file() {
420 .env("BAT_CONFIG_PATH", "bat.conf")
424 .stdout("dummy-pager-from-config\n");
429 // The output will be converted to UTF-8 with a leading UTF-8 BOM
432 .arg("--decorations=always")
433 .arg("test_UTF-16LE.txt")
436 .stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
440fn can_print_file_named_cache() {
450fn can_print_file_named_cache_with_additional_argument() {
456 .stdout("test\nhello world\n")
461fn can_print_file_starting_with_cache() {
471fn does_not_print_unwanted_file_named_cache() {
472 bat_with_config().arg("cach").assert().failure();
478 .arg("unicode-wrap.txt")
479 .arg("--style=numbers,snip")
480 .arg("--decorations=always")
481 .arg("--terminal-width=40")
485 " 1 ビタミンA ビタミンD ビタミンE ビ
491 3 고양이 고양이 고양이 고양이 고양이
501 5 1 บวก 2 บวก 3 บวก 4 บวก 5 บวก 6 บวก
502 7 บวก 8 บวก 9 บวก 10 บวก 11 บวก 12
503 บวก 13 บวก 14 บวก 15 บวก 16 บวก 17
506 7 Бельгия Болгария Чехия Дания Герман
507 ия Эстония Ирландия Греция Испания
508 Франция Хорватия Италия Кипр Латвия
509 Литва Люксембург Венгрия Мальта Ни
510 дерланды Австрия Польша Португалия
511 Румыния Словения Словакия Финляндия
512 Швеция Великобритания
520 .arg("multiline.txt")
521 .arg("--style=numbers,snip")
522 .arg("--decorations=always")
523 .arg("--line-range=1:2")
524 .arg("--line-range=4:")
525 .arg("--terminal-width=80")
531 ...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
538fn empty_file_leads_to_empty_output_with_grid_enabled() {
542 .arg("--decorations=always")
543 .arg("--terminal-width=80")
553 .arg("--decorations=always")
554 .arg("--style=header")
556 .arg("--file-name=foo")
559 .stdout("File: foo\n")
564fn filename_binary() {
567 .arg("--decorations=always")
568 .arg("--style=header")
570 .arg("--file-name=foo")
573 .stdout("File: foo <BINARY>\n")
580 .arg("--decorations=always")
581 .arg("--style=header")
584 .write_stdin("stdin\n")
585 .arg("--file-name=foo")
588 .stdout("File: foo\n")
593fn filename_stdin_binary() {
594 let vec = vec![0; 1];
596 .arg("--decorations=always")
597 .arg("--style=header")
599 .arg("--file-name=foo")
602 .stdout("File: foo <BINARY>\n")
607fn filename_multiple_ok() {
609 .arg("--decorations=always")
610 .arg("--style=header")
613 .arg("--file-name=foo")
614 .arg("single-line.txt")
615 .arg("--file-name=bar")
618 .stdout("File: foo\n\nFile: bar\n")
623fn filename_multiple_err() {
625 .arg("--decorations=always")
626 .arg("--style=header")
629 .arg("--file-name=foo")
630 .arg("single-line.txt")
638 .arg("--decorations=always")
639 .arg("--style=header")
641 .arg("single-line.txt")
643 .stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
647#[cfg(target_os = "linux")]
649fn file_with_invalid_utf8_filename() {
653 use std::os::unix::ffi::OsStrExt;
655 use tempdir::TempDir;
657 let tmp_dir = TempDir::new("bat_test").expect("can create temporary directory");
658 let file_path = tmp_dir
660 .join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));
662 let mut file = File::create(&file_path).expect("can create temporary file");
663 writeln!(file, "dummy content").expect("can write to file");
667 .arg(file_path.as_os_str())
670 .stdout("dummy content\n");
674fn do_not_panic_regression_tests() {
683 .arg("--color=always")
684 .arg(&format!("regression_tests/{}", filename))
691fn do_not_detect_different_syntax_for_stdin_and_files() {
692 let file = "regression_tests/issue_985.js";
694 let cmd_for_file = bat()
695 .arg("--color=always")
696 .arg("--map-syntax=*.js:Markdown")
697 .arg(&format!("--file-name={}", file))
698 .arg("--style=plain")
703 let cmd_for_stdin = bat()
704 .arg("--color=always")
705 .arg("--map-syntax=*.js:Markdown")
706 .arg("--style=plain")
707 .arg(&format!("--file-name={}", file))
708 .pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
714 from_utf8(&cmd_for_file.get_output().stdout).expect("output is valid utf-8"),
715 from_utf8(&cmd_for_stdin.get_output().stdout).expect("output is valid utf-8")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list