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 config_location_test() {
411 .env("BAT_CONFIG_PATH", "bat.conf")
412 .arg("--config-file")
415 .stdout("bat.conf\n");
419fn config_read_arguments_from_file() {
421 .env("BAT_CONFIG_PATH", "bat.conf")
425 .stdout(predicate::eq("dummy-pager-from-config\n").normalize());
430 // The output will be converted to UTF-8 with a leading UTF-8 BOM
433 .arg("--decorations=always")
434 .arg("test_UTF-16LE.txt")
437 .stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
441fn can_print_file_named_cache() {
451fn can_print_file_named_cache_with_additional_argument() {
457 .stdout("test\nhello world\n")
462fn can_print_file_starting_with_cache() {
472fn does_not_print_unwanted_file_named_cache() {
473 bat_with_config().arg("cach").assert().failure();
479 .arg("unicode-wrap.txt")
480 .arg("--style=numbers,snip")
481 .arg("--decorations=always")
482 .arg("--terminal-width=40")
486 " 1 ビタミンA ビタミンD ビタミンE ビ
492 3 고양이 고양이 고양이 고양이 고양이
502 5 1 บวก 2 บวก 3 บวก 4 บวก 5 บวก 6 บวก
503 7 บวก 8 บวก 9 บวก 10 บวก 11 บวก 12
504 บวก 13 บวก 14 บวก 15 บวก 16 บวก 17
507 7 Бельгия Болгария Чехия Дания Герман
508 ия Эстония Ирландия Греция Испания
509 Франция Хорватия Италия Кипр Латвия
510 Литва Люксембург Венгрия Мальта Ни
511 дерланды Австрия Польша Португалия
512 Румыния Словения Словакия Финляндия
513 Швеция Великобритания
521 .arg("multiline.txt")
522 .arg("--style=numbers,snip")
523 .arg("--decorations=always")
524 .arg("--line-range=1:2")
525 .arg("--line-range=4:")
526 .arg("--terminal-width=80")
532 ...─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ 8< ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
539fn empty_file_leads_to_empty_output_with_grid_enabled() {
543 .arg("--decorations=always")
544 .arg("--terminal-width=80")
554 .arg("--decorations=always")
555 .arg("--style=header")
557 .arg("--file-name=foo")
560 .stdout("File: foo\n")
565fn filename_binary() {
568 .arg("--decorations=always")
569 .arg("--style=header")
571 .arg("--file-name=foo")
574 .stdout("File: foo <BINARY>\n")
581 .arg("--decorations=always")
582 .arg("--style=header")
585 .write_stdin("stdin\n")
586 .arg("--file-name=foo")
589 .stdout("File: foo\n")
594fn filename_stdin_binary() {
595 let vec = vec![0; 1];
597 .arg("--decorations=always")
598 .arg("--style=header")
600 .arg("--file-name=foo")
603 .stdout("File: foo <BINARY>\n")
608fn filename_multiple_ok() {
610 .arg("--decorations=always")
611 .arg("--style=header")
614 .arg("--file-name=foo")
615 .arg("single-line.txt")
616 .arg("--file-name=bar")
619 .stdout("File: foo\n\nFile: bar\n")
624fn filename_multiple_err() {
626 .arg("--decorations=always")
627 .arg("--style=header")
630 .arg("--file-name=foo")
631 .arg("single-line.txt")
639 .arg("--decorations=always")
640 .arg("--style=header")
642 .arg("single-line.txt")
644 .stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
648#[cfg(target_os = "linux")]
650fn file_with_invalid_utf8_filename() {
654 use std::os::unix::ffi::OsStrExt;
656 use tempdir::TempDir;
658 let tmp_dir = TempDir::new("bat_test").expect("can create temporary directory");
659 let file_path = tmp_dir
661 .join(OsStr::from_bytes(b"test-invalid-utf8-\xC3(.rs"));
663 let mut file = File::create(&file_path).expect("can create temporary file");
664 writeln!(file, "dummy content").expect("can write to file");
668 .arg(file_path.as_os_str())
671 .stdout("dummy content\n");
675fn do_not_panic_regression_tests() {
684 .arg("--color=always")
685 .arg(&format!("regression_tests/{}", filename))
692fn do_not_detect_different_syntax_for_stdin_and_files() {
693 let file = "regression_tests/issue_985.js";
695 let cmd_for_file = bat()
696 .arg("--color=always")
697 .arg("--map-syntax=*.js:Markdown")
698 .arg(&format!("--file-name={}", file))
699 .arg("--style=plain")
704 let cmd_for_stdin = bat()
705 .arg("--color=always")
706 .arg("--map-syntax=*.js:Markdown")
707 .arg("--style=plain")
708 .arg(&format!("--file-name={}", file))
709 .pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
715 from_utf8(&cmd_for_file.get_output().stdout).expect("output is valid utf-8"),
716 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