on master help sign in
tests: Make mocked pagers work on Windows
e87c554Martin Nordholts
tests/integration_tests.rs+24−12
@@ -34,6 +34,18 @@ fn get_mocked_pagers_dir() -> PathBuf {
34 .join("mocked-pagers")
34 .join("mocked-pagers")
35}
35}
36
36
37+/// On Unix: 'most' -> 'most'
38+/// On Windows: 'most' -> 'most.bat'
39+fn mocked_pager(base: &str) -> String {
40+ if cfg!(windows) {
41+ let mut str = String::from(base);
42+ str.push_str(".bat");
43+ str
44+ } else {
45+ String::from(base)
46+ }
47+}
48+
37/// Prepends a directory to the PATH environment variable
49/// Prepends a directory to the PATH environment variable
38/// Returns the original value for later restoration
50/// Returns the original value for later restoration
39fn prepend_dir_to_path_env_var(dir: PathBuf) -> String {
51fn prepend_dir_to_path_env_var(dir: PathBuf) -> String {
@@ -64,14 +76,14 @@ fn with_mocked_versions_of_more_and_most_in_path(actual_test: fn()) {
64 let original_path = prepend_dir_to_path_env_var(get_mocked_pagers_dir());
76 let original_path = prepend_dir_to_path_env_var(get_mocked_pagers_dir());
65
77
66 // Make sure our own variants of 'more' and 'most' is used
78 // Make sure our own variants of 'more' and 'most' is used
67− Command::new("more")
79+ Command::new(mocked_pager("more"))
68 .assert()
80 .assert()
69 .success()
81 .success()
70− .stdout("I am more\n");
82+ .stdout(predicate::str::contains("I am more"));
71− Command::new("most")
83+ Command::new(mocked_pager("most"))
72 .assert()
84 .assert()
73 .success()
85 .success()
74− .stdout("I am most\n");
86+ .stdout(predicate::str::contains("I am most"));
75
87
76 // Now run the actual test
88 // Now run the actual test
77 actual_test();
89 actual_test();
@@ -478,9 +490,9 @@ fn pager_value_bat() {
478#[serial] // Because of PATH
490#[serial] // Because of PATH
479fn pager_most_from_pager_env_var() {
491fn pager_most_from_pager_env_var() {
480 with_mocked_versions_of_more_and_most_in_path(|| {
492 with_mocked_versions_of_more_and_most_in_path(|| {
481− // If the output is not "I am most\n" then we know 'most' is not used
493+ // If the output is not "I am most" then we know 'most' is not used
482 bat()
494 bat()
483− .env("PAGER", "most")
495+ .env("PAGER", mocked_pager("most"))
484 .arg("--paging=always")
496 .arg("--paging=always")
485 .arg("test.txt")
497 .arg("test.txt")
486 .assert()
498 .assert()
@@ -496,12 +508,12 @@ fn pager_most_from_pager_env_var() {
496fn pager_most_from_bat_pager_env_var() {
508fn pager_most_from_bat_pager_env_var() {
497 with_mocked_versions_of_more_and_most_in_path(|| {
509 with_mocked_versions_of_more_and_most_in_path(|| {
498 bat()
510 bat()
499− .env("BAT_PAGER", "most")
511+ .env("BAT_PAGER", mocked_pager("most"))
500 .arg("--paging=always")
512 .arg("--paging=always")
501 .arg("test.txt")
513 .arg("test.txt")
502 .assert()
514 .assert()
503 .success()
515 .success()
504− .stdout(predicate::eq("I am most\n").normalize());
516+ .stdout(predicate::str::contains("I am most"));
505 });
517 });
506}
518}
507
519
@@ -512,11 +524,11 @@ fn pager_most_from_pager_arg() {
512 with_mocked_versions_of_more_and_most_in_path(|| {
524 with_mocked_versions_of_more_and_most_in_path(|| {
513 bat()
525 bat()
514 .arg("--paging=always")
526 .arg("--paging=always")
515− .arg("--pager=most")
527+ .arg(format!("--pager={}", mocked_pager("most")))
516 .arg("test.txt")
528 .arg("test.txt")
517 .assert()
529 .assert()
518 .success()
530 .success()
519− .stdout(predicate::eq("I am most\n").normalize());
531+ .stdout(predicate::str::contains("I am most"));
520 });
532 });
521}
533}
522
534
@@ -526,7 +538,7 @@ fn pager_most_from_pager_arg() {
526fn pager_most_with_arg() {
538fn pager_most_with_arg() {
527 with_mocked_versions_of_more_and_most_in_path(|| {
539 with_mocked_versions_of_more_and_most_in_path(|| {
528 bat()
540 bat()
529− .env("PAGER", "most -w")
541+ .env("PAGER", format!("{} -w", mocked_pager("most")))
530 .arg("--paging=always")
542 .arg("--paging=always")
531 .arg("test.txt")
543 .arg("test.txt")
532 .assert()
544 .assert()
@@ -541,7 +553,7 @@ fn pager_most_with_arg() {
541fn pager_more() {
553fn pager_more() {
542 with_mocked_versions_of_more_and_most_in_path(|| {
554 with_mocked_versions_of_more_and_most_in_path(|| {
543 bat()
555 bat()
544− .env("PAGER", "more")
556+ .env("PAGER", mocked_pager("more"))
545 .arg("--paging=always")
557 .arg("--paging=always")
546 .arg("test.txt")
558 .arg("test.txt")
547 .assert()
559 .assert()
tests/mocked-pagers/more+1−1
@@ -1,2 +1,2 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−echo "I am more"
2+echo I am more
tests/mocked-pagers/more.batnew file+1
@@ -0,0 +1 @@
1+ECHO I am more
tests/mocked-pagers/most+1−1
@@ -1,2 +1,2 @@
1#!/usr/bin/env bash
1#!/usr/bin/env bash
2−echo "I am most"
2+echo I am most
tests/mocked-pagers/most.batnew file+1
@@ -0,0 +1 @@
1+ECHO I am most