Add regression test for detected syntax differing for stdin and files

This commit is contained in:
Ethan P 2020-05-13 02:51:49 -07:00
parent 157b8dd848
commit 82981c9663
No known key found for this signature in database
GPG key ID: 6963FD04F6CF35EA
2 changed files with 44 additions and 0 deletions

View file

@ -0,0 +1,5 @@
// This test should be considered a failure if the detected syntax differs between the following two commands:
/*
# bat --map-syntax '*.js:Markdown' --file-name 'issue_985.js' < issue_985.js
# bat --map-syntax '*.js:Markdown' --file-name 'issue_985.js' issue_985.js
*/

View file

@ -1,4 +1,8 @@
use assert_cmd::Command;
use std::path::Path;
use std::str::from_utf8;
const EXAMPLES_DIR: &str = "tests/examples";
fn bat_with_config() -> Command {
let mut cmd = Command::cargo_bin("bat").unwrap();
@ -670,3 +674,38 @@ fn do_not_panic_regression_tests() {
.success();
}
}
#[test]
fn do_not_detect_different_syntax_for_stdin_and_files() {
let file = "regression_tests/issue_985.js";
let output_for_file = bat()
.arg("--color=always")
.arg("--map-syntax=*.js:Markdown")
.arg(&format!("--file-name={}", file))
.arg("--style=plain")
.arg(file)
.assert()
.success()
.get_output()
.stdout
.clone();
let output_for_stdin = bat()
.arg("--color=always")
.arg("--map-syntax=*.js:Markdown")
.arg("--style=plain")
.arg(&format!("--file-name={}", file))
.pipe_stdin(Path::new(EXAMPLES_DIR).join(file))
.unwrap()
.assert()
.success()
.get_output()
.stdout
.clone();
assert_eq!(
from_utf8(&output_for_file).unwrap(),
from_utf8(&output_for_stdin).unwrap()
);
}