@@ -34,6 +34,14 @@ use utils::mocked_pagers;
3434
3535const EXAMPLES_DIR : & str = "tests/examples" ;
3636
37+ fn get_config ( ) -> & ' static str {
38+ if cfg ! ( windows) {
39+ "bat-windows.conf"
40+ } else {
41+ "bat.conf"
42+ }
43+ }
44+
3745#[ test]
3846fn basic ( ) {
3947 bat ( )
@@ -589,37 +597,49 @@ fn do_not_exit_directory() {
589597}
590598
591599#[ test]
600+ #[ serial]
592601fn pager_basic ( ) {
593- bat ( )
594- . env ( "PAGER" , "echo pager-output" )
595- . arg ( "--paging=always" )
596- . arg ( "test.txt" )
597- . assert ( )
598- . success ( )
599- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
602+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
603+ bat ( )
604+ . env ( "PAGER" , mocked_pagers:: from ( "echo pager-output" ) )
605+ . arg ( "--paging=always" )
606+ . arg ( "test.txt" )
607+ . assert ( )
608+ . success ( )
609+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
610+ } ) ;
600611}
601612
602613#[ test]
614+ #[ serial]
603615fn pager_basic_arg ( ) {
604- bat ( )
605- . arg ( "--pager=echo pager-output" )
606- . arg ( "--paging=always" )
607- . arg ( "test.txt" )
608- . assert ( )
609- . success ( )
610- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
616+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
617+ bat ( )
618+ . arg ( format ! (
619+ "--pager={}" ,
620+ mocked_pagers:: from( "echo pager-output" )
621+ ) )
622+ . arg ( "--paging=always" )
623+ . arg ( "test.txt" )
624+ . assert ( )
625+ . success ( )
626+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
627+ } ) ;
611628}
612629
613630#[ test]
631+ #[ serial]
614632fn pager_overwrite ( ) {
615- bat ( )
616- . env ( "PAGER" , "echo other-pager" )
617- . env ( "BAT_PAGER" , "echo pager-output" )
618- . arg ( "--paging=always" )
619- . arg ( "test.txt" )
620- . assert ( )
621- . success ( )
622- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
633+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
634+ bat ( )
635+ . env ( "PAGER" , mocked_pagers:: from ( "echo other-pager" ) )
636+ . env ( "BAT_PAGER" , mocked_pagers:: from ( "echo pager-output" ) )
637+ . arg ( "--paging=always" )
638+ . arg ( "test.txt" )
639+ . assert ( )
640+ . success ( )
641+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
642+ } ) ;
623643}
624644
625645#[ test]
@@ -635,55 +655,73 @@ fn pager_disable() {
635655}
636656
637657#[ test]
658+ #[ serial]
638659fn pager_arg_override_env_withconfig ( ) {
639- bat_with_config ( )
640- . env ( "BAT_CONFIG_PATH" , "bat.conf" )
641- . env ( "PAGER" , "echo another-pager" )
642- . env ( "BAT_PAGER" , "echo other-pager" )
643- . arg ( "--pager=echo pager-output" )
644- . arg ( "--paging=always" )
645- . arg ( "test.txt" )
646- . assert ( )
647- . success ( )
648- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
660+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
661+ bat_with_config ( )
662+ . env ( "BAT_CONFIG_PATH" , get_config ( ) )
663+ . env ( "PAGER" , mocked_pagers:: from ( "echo another-pager" ) )
664+ . env ( "BAT_PAGER" , mocked_pagers:: from ( "echo other-pager" ) )
665+ . arg ( format ! (
666+ "--pager={}" ,
667+ mocked_pagers:: from( "echo pager-output" )
668+ ) )
669+ . arg ( "--paging=always" )
670+ . arg ( "test.txt" )
671+ . assert ( )
672+ . success ( )
673+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
674+ } ) ;
649675}
650676
651677#[ test]
678+ #[ serial]
652679fn pager_arg_override_env_noconfig ( ) {
653- bat ( )
654- . env ( "PAGER" , "echo another-pager" )
655- . env ( "BAT_PAGER" , "echo other-pager" )
656- . arg ( "--pager=echo pager-output" )
657- . arg ( "--paging=always" )
658- . arg ( "test.txt" )
659- . assert ( )
660- . success ( )
661- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
680+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
681+ bat ( )
682+ . env ( "PAGER" , mocked_pagers:: from ( "echo another-pager" ) )
683+ . env ( "BAT_PAGER" , mocked_pagers:: from ( "echo other-pager" ) )
684+ . arg ( format ! (
685+ "--pager={}" ,
686+ mocked_pagers:: from( "echo pager-output" )
687+ ) )
688+ . arg ( "--paging=always" )
689+ . arg ( "test.txt" )
690+ . assert ( )
691+ . success ( )
692+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
693+ } ) ;
662694}
663695
664696#[ test]
697+ #[ serial]
665698fn pager_env_bat_pager_override_config ( ) {
666- bat_with_config ( )
667- . env ( "BAT_CONFIG_PATH" , "bat.conf" )
668- . env ( "PAGER" , "echo other-pager" )
669- . env ( "BAT_PAGER" , "echo pager-output" )
670- . arg ( "--paging=always" )
671- . arg ( "test.txt" )
672- . assert ( )
673- . success ( )
674- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
699+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
700+ bat_with_config ( )
701+ . env ( "BAT_CONFIG_PATH" , get_config ( ) )
702+ . env ( "PAGER" , mocked_pagers:: from ( "echo other-pager" ) )
703+ . env ( "BAT_PAGER" , mocked_pagers:: from ( "echo pager-output" ) )
704+ . arg ( "--paging=always" )
705+ . arg ( "test.txt" )
706+ . assert ( )
707+ . success ( )
708+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
709+ } ) ;
675710}
676711
677712#[ test]
713+ #[ serial]
678714fn pager_env_pager_nooverride_config ( ) {
679- bat_with_config ( )
680- . env ( "BAT_CONFIG_PATH" , "bat.conf" )
681- . env ( "PAGER" , "echo other-pager" )
682- . arg ( "--paging=always" )
683- . arg ( "test.txt" )
684- . assert ( )
685- . success ( )
686- . stdout ( predicate:: eq ( "dummy-pager-from-config\n " ) . normalize ( ) ) ;
715+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
716+ bat_with_config ( )
717+ . env ( "BAT_CONFIG_PATH" , get_config ( ) )
718+ . env ( "PAGER" , mocked_pagers:: from ( "echo other-pager" ) )
719+ . arg ( "--paging=always" )
720+ . arg ( "test.txt" )
721+ . assert ( )
722+ . success ( )
723+ . stdout ( predicate:: str:: contains ( "dummy-pager-from-config\n " ) . normalize ( ) ) ;
724+ } ) ;
687725}
688726
689727#[ test]
@@ -809,15 +847,18 @@ fn alias_pager_disable() {
809847}
810848
811849#[ test]
850+ #[ serial]
812851fn alias_pager_disable_long_overrides_short ( ) {
813- bat ( )
814- . env ( "PAGER" , "echo pager-output" )
815- . arg ( "-P" )
816- . arg ( "--paging=always" )
817- . arg ( "test.txt" )
818- . assert ( )
819- . success ( )
820- . stdout ( predicate:: eq ( "pager-output\n " ) . normalize ( ) ) ;
852+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
853+ bat ( )
854+ . env ( "PAGER" , mocked_pagers:: from ( "echo pager-output" ) )
855+ . arg ( "-P" )
856+ . arg ( "--paging=always" )
857+ . arg ( "test.txt" )
858+ . assert ( )
859+ . success ( )
860+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
861+ } ) ;
821862}
822863
823864#[ test]
@@ -844,14 +885,17 @@ fn pager_failed_to_parse() {
844885}
845886
846887#[ test]
888+ #[ serial]
847889fn env_var_bat_paging ( ) {
848- bat ( )
849- . env ( "BAT_PAGER" , "echo pager-output" )
850- . env ( "BAT_PAGING" , "always" )
851- . arg ( "test.txt" )
852- . assert ( )
853- . success ( )
854- . stdout ( predicate:: eq ( "pager-output\n " ) ) ;
890+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
891+ bat ( )
892+ . env ( "BAT_PAGER" , mocked_pagers:: from ( "echo pager-output" ) )
893+ . env ( "BAT_PAGING" , "always" )
894+ . arg ( "test.txt" )
895+ . assert ( )
896+ . success ( )
897+ . stdout ( predicate:: str:: contains ( "pager-output\n " ) . normalize ( ) ) ;
898+ } ) ;
855899}
856900
857901#[ test]
@@ -912,13 +956,16 @@ fn config_location_from_bat_config_dir_variable() {
912956}
913957
914958#[ test]
959+ #[ serial]
915960fn config_read_arguments_from_file ( ) {
916- bat_with_config ( )
917- . env ( "BAT_CONFIG_PATH" , "bat.conf" )
918- . arg ( "test.txt" )
919- . assert ( )
920- . success ( )
921- . stdout ( predicate:: eq ( "dummy-pager-from-config\n " ) . normalize ( ) ) ;
961+ mocked_pagers:: with_mocked_versions_of_more_and_most_in_path ( || {
962+ bat_with_config ( )
963+ . env ( "BAT_CONFIG_PATH" , get_config ( ) )
964+ . arg ( "test.txt" )
965+ . assert ( )
966+ . success ( )
967+ . stdout ( predicate:: str:: contains ( "dummy-pager-from-config\n " ) . normalize ( ) ) ;
968+ } ) ;
922969}
923970
924971#[ cfg( unix) ]
0 commit comments