mirror of
https://github.com/sharkdp/bat
synced 2024-11-18 15:26:16 +00:00
Tests ~ add instrumentation to visualize text differences in failing tests
This commit is contained in:
parent
377913cd05
commit
f8ed8aa74b
@ -24,9 +24,14 @@ fn bat() -> Command {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn basic() {
|
fn basic() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\n")
|
.stdout("hello world\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -34,168 +39,216 @@ fn basic() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn stdin() {
|
fn stdin() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.write_stdin("foo\nbar\n")
|
.write_stdin("foo\nbar\n")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("foo\nbar\n");
|
.stdout("foo\nbar\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate() {
|
fn concatenate() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\nhello world\n");
|
.stdout("hello world\nhello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_stdin() {
|
fn concatenate_stdin() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("-")
|
.arg("-")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.write_stdin("stdin\n")
|
.write_stdin("stdin\n")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\nstdin\nhello world\n");
|
.stdout("hello world\nstdin\nhello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_empty_first() {
|
fn concatenate_empty_first() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\n");
|
.stdout("hello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_empty_last() {
|
fn concatenate_empty_last() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\n");
|
.stdout("hello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_empty_both() {
|
fn concatenate_empty_both() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("");
|
.stdout("");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_empty_between() {
|
fn concatenate_empty_between() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\nhello world\n");
|
.stdout("hello world\nhello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_empty_first_and_last() {
|
fn concatenate_empty_first_and_last() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\n");
|
.stdout("hello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_single_line() {
|
fn concatenate_single_line() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("single-line.txt")
|
.arg("single-line.txt")
|
||||||
.arg("single-line.txt")
|
.arg("single-line.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("Single LineSingle Line");
|
.stdout("Single LineSingle Line");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn concatenate_single_line_empty() {
|
fn concatenate_single_line_empty() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("single-line.txt")
|
.arg("single-line.txt")
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.arg("single-line.txt")
|
.arg("single-line.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("Single LineSingle Line");
|
.stdout("Single LineSingle Line");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn line_numbers() {
|
fn line_numbers() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("multiline.txt")
|
.arg("multiline.txt")
|
||||||
.arg("--style=numbers")
|
.arg("--style=numbers")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
|
.stdout(" 1 line 1\n 2 line 2\n 3 line 3\n 4 line 4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn line_range_2_3() {
|
fn line_range_2_3() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("multiline.txt")
|
.arg("multiline.txt")
|
||||||
.arg("--line-range=2:3")
|
.arg("--line-range=2:3")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("line 2\nline 3\n");
|
.stdout("line 2\nline 3\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn line_range_first_two() {
|
fn line_range_first_two() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("multiline.txt")
|
.arg("multiline.txt")
|
||||||
.arg("--line-range=:2")
|
.arg("--line-range=:2")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("line 1\nline 2\n");
|
.stdout("line 1\nline 2\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn line_range_last_3() {
|
fn line_range_last_3() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("multiline.txt")
|
.arg("multiline.txt")
|
||||||
.arg("--line-range=2:")
|
.arg("--line-range=2:")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("line 2\nline 3\nline 4\n");
|
.stdout("line 2\nline 3\nline 4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn line_range_multiple() {
|
fn line_range_multiple() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("multiline.txt")
|
.arg("multiline.txt")
|
||||||
.arg("--line-range=1:2")
|
.arg("--line-range=1:2")
|
||||||
.arg("--line-range=4:4")
|
.arg("--line-range=4:4")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("line 1\nline 2\nline 4\n");
|
.stdout("line 1\nline 2\nline 4\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_numbers() {
|
fn tabs_numbers() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=4")
|
.arg("--tabs=4")
|
||||||
.arg("--style=numbers")
|
.arg("--style=numbers")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 1 2 3 4
|
" 1 1 2 3 4
|
||||||
@ -213,12 +266,15 @@ fn tabs_numbers() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_passthrough_wrapped() {
|
fn tabs_passthrough_wrapped() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=0")
|
.arg("--tabs=0")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 2 3 4
|
" 1 2 3 4
|
||||||
@ -236,12 +292,15 @@ fn tabs_passthrough_wrapped() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_4_wrapped() {
|
fn tabs_4_wrapped() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=4")
|
.arg("--tabs=4")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 2 3 4
|
" 1 2 3 4
|
||||||
@ -259,12 +318,15 @@ fn tabs_4_wrapped() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_8_wrapped() {
|
fn tabs_8_wrapped() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=8")
|
.arg("--tabs=8")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 2 3 4
|
" 1 2 3 4
|
||||||
@ -282,12 +344,15 @@ fn tabs_8_wrapped() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_passthrough() {
|
fn tabs_passthrough() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=0")
|
.arg("--tabs=0")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 2 3 4
|
" 1 2 3 4
|
||||||
@ -305,12 +370,15 @@ fn tabs_passthrough() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_4() {
|
fn tabs_4() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=4")
|
.arg("--tabs=4")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 2 3 4
|
" 1 2 3 4
|
||||||
@ -328,12 +396,15 @@ fn tabs_4() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn tabs_8() {
|
fn tabs_8() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("tabs.txt")
|
.arg("tabs.txt")
|
||||||
.arg("--tabs=8")
|
.arg("--tabs=8")
|
||||||
.arg("--style=plain")
|
.arg("--style=plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 2 3 4
|
" 1 2 3 4
|
||||||
@ -361,65 +432,83 @@ fn fail_directory() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn do_not_exit_directory() {
|
fn do_not_exit_directory() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("sub_directory")
|
.arg("sub_directory")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.stdout("hello world\n")
|
.stdout("hello world\n")
|
||||||
.failure();
|
.failure();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pager_basic() {
|
fn pager_basic() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.env("PAGER", "printf pager-output")
|
.env("PAGER", "printf pager-output")
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("pager-output");
|
.stdout("pager-output");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pager_overwrite() {
|
fn pager_overwrite() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.env("PAGER", "printf other-pager")
|
.env("PAGER", "printf other-pager")
|
||||||
.env("BAT_PAGER", "printf pager-output")
|
.env("BAT_PAGER", "printf pager-output")
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("pager-output");
|
.stdout("pager-output");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn pager_disable() {
|
fn pager_disable() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.env("PAGER", "printf other-pager")
|
.env("PAGER", "printf other-pager")
|
||||||
.env("BAT_PAGER", "")
|
.env("BAT_PAGER", "")
|
||||||
.arg("--paging=always")
|
.arg("--paging=always")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("hello world\n");
|
.stdout("hello world\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_location_test() {
|
fn config_location_test() {
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.env("BAT_CONFIG_PATH", "bat.conf")
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
||||||
.arg("--config-file")
|
.arg("--config-file")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("bat.conf\n");
|
.stdout("bat.conf\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn config_read_arguments_from_file() {
|
fn config_read_arguments_from_file() {
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.env("BAT_CONFIG_PATH", "bat.conf")
|
.env("BAT_CONFIG_PATH", "bat.conf")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("dummy-pager-from-config");
|
.stdout("dummy-pager-from-config");
|
||||||
}
|
}
|
||||||
@ -427,20 +516,28 @@ fn config_read_arguments_from_file() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn utf16() {
|
fn utf16() {
|
||||||
// The output will be converted to UTF-8 with a leading UTF-8 BOM
|
// The output will be converted to UTF-8 with a leading UTF-8 BOM
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("--plain")
|
.arg("--plain")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("test_UTF-16LE.txt")
|
.arg("test_UTF-16LE.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
|
.stdout(std::str::from_utf8(b"\xEF\xBB\xBFhello world\n").unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_print_file_named_cache() {
|
fn can_print_file_named_cache() {
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.arg("cache")
|
.arg("cache")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("test\n")
|
.stdout("test\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -448,10 +545,15 @@ fn can_print_file_named_cache() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_print_file_named_cache_with_additional_argument() {
|
fn can_print_file_named_cache_with_additional_argument() {
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.arg("cache")
|
.arg("cache")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("test\nhello world\n")
|
.stdout("test\nhello world\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -459,9 +561,14 @@ fn can_print_file_named_cache_with_additional_argument() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_print_file_starting_with_cache() {
|
fn can_print_file_starting_with_cache() {
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.arg("cache.c")
|
.arg("cache.c")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("test\n")
|
.stdout("test\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -474,12 +581,15 @@ fn does_not_print_unwanted_file_named_cache() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn unicode_wrap() {
|
fn unicode_wrap() {
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.arg("unicode-wrap.txt")
|
.arg("unicode-wrap.txt")
|
||||||
.arg("--style=numbers,snip")
|
.arg("--style=numbers,snip")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--terminal-width=40")
|
.arg("--terminal-width=40")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 ビタミンA ビタミンD ビタミンE ビ
|
" 1 ビタミンA ビタミンD ビタミンE ビ
|
||||||
@ -516,14 +626,17 @@ fn unicode_wrap() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn snip() {
|
fn snip() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("multiline.txt")
|
.arg("multiline.txt")
|
||||||
.arg("--style=numbers,snip")
|
.arg("--style=numbers,snip")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--line-range=1:2")
|
.arg("--line-range=1:2")
|
||||||
.arg("--line-range=4:")
|
.arg("--line-range=4:")
|
||||||
.arg("--terminal-width=80")
|
.arg("--terminal-width=80")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout(
|
.stdout(
|
||||||
" 1 line 1
|
" 1 line 1
|
||||||
@ -536,25 +649,33 @@ fn snip() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn empty_file_leads_to_empty_output_with_grid_enabled() {
|
fn empty_file_leads_to_empty_output_with_grid_enabled() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("empty.txt")
|
.arg("empty.txt")
|
||||||
.arg("--style=grid")
|
.arg("--style=grid")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--terminal-width=80")
|
.arg("--terminal-width=80")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("");
|
.stdout("");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn filename_basic() {
|
fn filename_basic() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--style=header")
|
.arg("--style=header")
|
||||||
.arg("-r=0:0")
|
.arg("-r=0:0")
|
||||||
.arg("--file-name=foo")
|
.arg("--file-name=foo")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("File: foo\n")
|
.stdout("File: foo\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -562,13 +683,18 @@ fn filename_basic() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn filename_binary() {
|
fn filename_binary() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("test.binary")
|
.arg("test.binary")
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--style=header")
|
.arg("--style=header")
|
||||||
.arg("-r=0:0")
|
.arg("-r=0:0")
|
||||||
.arg("--file-name=foo")
|
.arg("--file-name=foo")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("File: foo <BINARY>\n")
|
.stdout("File: foo <BINARY>\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -576,14 +702,19 @@ fn filename_binary() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn filename_stdin() {
|
fn filename_stdin() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--style=header")
|
.arg("--style=header")
|
||||||
.arg("-r=0:0")
|
.arg("-r=0:0")
|
||||||
.arg("-")
|
.arg("-")
|
||||||
.write_stdin("stdin\n")
|
.write_stdin("stdin\n")
|
||||||
.arg("--file-name=foo")
|
.arg("--file-name=foo")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("File: foo\n")
|
.stdout("File: foo\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -592,12 +723,17 @@ fn filename_stdin() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn filename_stdin_binary() {
|
fn filename_stdin_binary() {
|
||||||
let vec = vec![0; 1];
|
let vec = vec![0; 1];
|
||||||
bat_with_config()
|
let assert = bat_with_config()
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--style=header")
|
.arg("--style=header")
|
||||||
.write_stdin(vec)
|
.write_stdin(vec)
|
||||||
.arg("--file-name=foo")
|
.arg("--file-name=foo")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("File: foo <BINARY>\n")
|
.stdout("File: foo <BINARY>\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -605,7 +741,7 @@ fn filename_stdin_binary() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn filename_multiple_ok() {
|
fn filename_multiple_ok() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--style=header")
|
.arg("--style=header")
|
||||||
.arg("-r=0:0")
|
.arg("-r=0:0")
|
||||||
@ -613,7 +749,12 @@ fn filename_multiple_ok() {
|
|||||||
.arg("--file-name=foo")
|
.arg("--file-name=foo")
|
||||||
.arg("single-line.txt")
|
.arg("single-line.txt")
|
||||||
.arg("--file-name=bar")
|
.arg("--file-name=bar")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("File: foo\n\nFile: bar\n")
|
.stdout("File: foo\n\nFile: bar\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
@ -634,12 +775,17 @@ fn filename_multiple_err() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn header_padding() {
|
fn header_padding() {
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg("--decorations=always")
|
.arg("--decorations=always")
|
||||||
.arg("--style=header")
|
.arg("--style=header")
|
||||||
.arg("test.txt")
|
.arg("test.txt")
|
||||||
.arg("single-line.txt")
|
.arg("single-line.txt")
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
let stderr = String::from_utf8_lossy(&assert.get_output().stderr);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
println!("stderr={:#?}", stderr);
|
||||||
|
assert
|
||||||
.stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
|
.stdout("File: test.txt\nhello world\n\nFile: single-line.txt\nSingle Line\n")
|
||||||
.stderr("");
|
.stderr("");
|
||||||
}
|
}
|
||||||
@ -663,9 +809,12 @@ fn file_with_invalid_utf8_filename() {
|
|||||||
writeln!(file, "dummy content").expect("can write to file");
|
writeln!(file, "dummy content").expect("can write to file");
|
||||||
}
|
}
|
||||||
|
|
||||||
bat()
|
let assert = bat()
|
||||||
.arg(file_path.as_os_str())
|
.arg(file_path.as_os_str())
|
||||||
.assert()
|
.assert();
|
||||||
|
let stdout = String::from_utf8_lossy(&assert.get_output().stdout);
|
||||||
|
println!("stdout={:#?}", stdout);
|
||||||
|
assert
|
||||||
.success()
|
.success()
|
||||||
.stdout("dummy content\n");
|
.stdout("dummy content\n");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user