1use assert_cmd::Command;
2use predicates::{prelude::predicate,str::PredicateStrExt};
4use std::str::from_utf8;
6const EXAMPLES_DIR: &str = "tests/examples";
8fn bat_with_config() -> Command {
9 let mut cmd = Command::cargo_bin("bat").unwrap();
10 cmd.current_dir("tests/examples");
11 cmd.env_remove("PAGER");
12 cmd.env_remove("BAT_PAGER");
13 cmd.env_remove("BAT_CONFIG_PATH");
14 cmd.env_remove("BAT_STYLE");
15 cmd.env_remove("BAT_THEME");
16 cmd.env_remove("BAT_TABS");
21 let mut cmd = bat_with_config();
22 cmd.arg("--no-config");
32 .stdout("hello world\n")
39 .write_stdin("foo\nbar\n")
42 .stdout("foo\nbar\n");
52 .stdout("hello world\nhello world\n");
56fn concatenate_stdin() {
61 .write_stdin("stdin\n")
64 .stdout("hello world\nstdin\nhello world\n");
68fn concatenate_empty_first() {
74 .stdout("hello world\n");
78fn concatenate_empty_last() {
84 .stdout("hello world\n");
88fn concatenate_empty_both() {
98fn concatenate_empty_between() {
105 .stdout("hello world\nhello world\n");
109fn concatenate_empty_first_and_last() {
116 .stdout("hello world\n");
120fn concatenate_single_line() {
122 .arg("single-line.txt")
123 .arg("single-line.txt")
126 .stdout("Single LineSingle Line");
130fn concatenate_single_line_empty() {
132 .arg("single-line.txt")
134 .arg("single-line.txt")
137 .stdout("Single LineSingle Line");
143 .arg("multiline.txt")
144 .arg("--style=numbers")
145 .arg("--decorations=always")
148 .stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
154 .arg("multiline.txt")
155 .arg("--line-range=2:3")
158 .stdout("line 2\nline 3\n");
162fn line_range_first_two() {
164 .arg("multiline.txt")
165 .arg("--line-range=:2")
168 .stdout("line 1\nline 2\n");
172fn line_range_last_3() {
174 .arg("multiline.txt")
175 .arg("--line-range=2:")
178 .stdout("line 2\nline 3\nline 4\n");
182fn line_range_multiple() {
184 .arg("multiline.txt")
185 .arg("--line-range=1:2")
186 .arg("--line-range=4:4")
189 .stdout("line 1\nline 2\nline 4\n");
197 .arg("--style=numbers")
198 .arg("--decorations=always")
216fn tabs_passthrough_wrapped() {
220 .arg("--style=plain")
221 .arg("--decorations=always")
243 .arg("--style=plain")
244 .arg("--decorations=always")
266 .arg("--style=plain")
267 .arg("--decorations=always")
285fn tabs_passthrough() {
289 .arg("--style=plain")
290 .arg("--decorations=always")
312 .arg("--style=plain")
313 .arg("--decorations=always")
335 .arg("--style=plain")
336 .arg("--decorations=always")
354fn fail_non_existing() {
355 bat().arg("non-existing-file").assert().failure();
360 bat().arg("sub_directory").assert().failure();
364fn do_not_exit_directory() {
366 .arg("sub_directory")
369 .stdout("hello world\n")
376 .env("PAGER", "echo pager-output")
377 .arg("--paging=always")
381 .stdout(predicate::eq("pager-output\n").normalize());
385fn pager_overwrite() {
387 .env("PAGER", "echo other-pager")
388 .env("BAT_PAGER", "echo pager-output")
389 .arg("--paging=always")
393 .stdout(predicate::eq("pager-output\n").normalize());
399 .env("PAGER", "echo other-pager")
400 .env("BAT_PAGER", "")
401 .arg("--paging=always")
405 .stdout(predicate::eq("hello world\n").normalize());
409fn alias_pager_disable() {
411 .env("PAGER", "echo other-pager")
416 .stdout(predicate::eq("hello world\n").normalize());
420fn alias_pager_disable_long_overrides_short() {
422 .env("PAGER", "echo pager-output")
424 .arg("--paging=always")
428 .stdout(predicate::eq("pager-output\n").normalize());
432fn config_location_test() {
434 .env("BAT_CONFIG_PATH", "bat.conf")
435 .arg("--config-file")
438 .stdout("bat.conf\n");
442fn config_read_arguments_from_file() {
444 .env("BAT_CONFIG_PATH", "bat.conf")
448 .stdout(predicate::eq("dummy-pager-from-config\n").normalize());
453 // The output will be converted to UTF-8 with a leading UTF-8 BOM
456 .arg("--decorations=always")
457 .arg("test_UTF-16LE.txt")
460 .stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
464fn can_print_file_named_cache() {
474fn can_print_file_named_cache_with_additional_argument() {
480 .stdout("test\nhello world\n")
485fn can_print_file_starting_with_cache() {
495fn does_not_print_unwanted_file_named_cache() {
496 bat_with_config().arg("cach").assert().failure();
502 .arg("unicode-wrap.txt")
503 .arg("--style=numbers,snip")
504 .arg("--decorations=always")
505 .arg("--terminal-width=40")
509 " 1 ビタミンA ビタミンD ビタミンE ビ
515 3 고양이 고양이 고양이 고양이 고양이
525 5 1 บวก 2 บวก 3 บวก 4 บวก 5 บวก 6 บวก
526 7 บวก 8 บวก 9 บวก 10 บวก 11 บวก 12
527 บวก 13 บวก 14 บวก 15 บวก 16 บวก 17
530 7 Бельгия Болгария Чехия Дания Герман
531 ия Эстония Ирландия Греция Испания
532 Франция Хорватия Италия Кипр Латвия
533 Литва Люксембург Венгрия Мальта Ни
534 дерланды Австрия Польша Португалия
535 Румыния Словения Словакия Финляндия
536 Швеция Великобритания
544 .arg("multiline.txt")
545 .arg("--style=numbers,snip")
546 .arg("--decorations=always")
547 .arg("--line-range=1:2")
548 .arg("--line-range=4:")
549 .arg("--terminal-width=80")
555 ...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
562fn empty_file_leads_to_empty_output_with_grid_enabled() {
566 .arg("--decorations=always")
567 .arg("--terminal-width=80")
577 .arg("--decorations=always")
578 .arg("--style=header")
580 .arg("--file-name=foo")
583 .stdout("File: foo\n")
588fn filename_binary() {
591 .arg("--decorations=always")
592 .arg("--style=header")
594 .arg("--file-name=foo")
597 .stdout("File: foo <BINARY>\n")
604 .arg("--decorations=always")
605 .arg("--style=header")
608 .write_stdin("stdin\n")
609 .arg("--file-name=foo")
612 .stdout("File: foo\n")
617fn filename_stdin_binary() {
618 let vec = vec![0; 1];
620 .arg("--decorations=always")
621 .arg("--style=header")
623 .arg("--file-name=foo")
626 .stdout("File: foo <BINARY>\n")
631fn filename_multiple_ok() {
633 .arg("--decorations=always")
634 .arg("--style=header")
637 .arg("--file-name=foo")
638 .arg("single-line.txt")
639 .arg("--file-name=bar")
642 .stdout("File: foo\n\nFile: bar\n")
647fn filename_multiple_err() {
649 .arg("--decorations=always")
650 .arg("--style=header")
653 .arg("--file-name=foo")
654 .arg("single-line.txt")
662 .arg("--decorations=always")
663 .arg("--style=header")
665 .arg("single-line.txt")
667 .stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
671#[cfg(target_os = "linux")]
673fn file_with_invalid_utf8_filename() {
677 use std::os::unix::ffi::OsStrExt;
679 use tempdir::TempDir;
681 let tmp_dir = TempDir::new("bat_test").expect("can create temporary directory");
682 let file_path = tmp_dir
684 .join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));
686 let mut file = File::create(&file_path).expect("can create temporary file");
687 writeln!(file, "dummy content").expect("can write to file");
691 .arg(file_path.as_os_str())
694 .stdout("dummy content\n");
698fn do_not_panic_regression_tests() {
707 .arg("--color=always")
708 .arg(&format!("regression_tests/{}", filename))
715fn do_not_detect_different_syntax_for_stdin_and_files() {
716 let file = "regression_tests/issue_985.js";
718 let cmd_for_file = bat()
719 .arg("--color=always")
720 .arg("--map-syntax=*.js:Markdown")
721 .arg(&format!("--file-name={}", file))
722 .arg("--style=plain")
727 let cmd_for_stdin = bat()
728 .arg("--color=always")
729 .arg("--map-syntax=*.js:Markdown")
730 .arg("--style=plain")
731 .arg(&format!("--file-name={}", file))
732 .pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
738 from_utf8(&cmd_for_file.get_output().stdout).expect("output is valid utf-8"),
739 from_utf8(&cmd_for_stdin.get_output().stdout).expect("output is valid utf-8")
747 .arg("nonprintable.txt")
749 .stdout("hello·world␊\n├──┤␍␀␇␈␛")
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