File tree Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Expand file tree Collapse file tree 2 files changed +34
-3
lines changed Original file line number Diff line number Diff line change 1- use assert_cmd:: Command ;
1+ use assert_cmd:: assert:: OutputAssertExt ;
2+ use assert_cmd:: cargo:: CommandCargoExt ;
23use predicates:: { prelude:: predicate, str:: PredicateStrExt } ;
4+ use std:: fs:: File ;
35use std:: path:: Path ;
6+ use std:: process:: { Command , Stdio } ;
47use std:: str:: from_utf8;
58
69const EXAMPLES_DIR : & str = "tests/examples" ;
710
8- fn bat_with_config ( ) -> Command {
11+ fn bat_as_std ( ) -> Command {
912 let mut cmd = Command :: cargo_bin ( "bat" ) . unwrap ( ) ;
1013 cmd. current_dir ( "tests/examples" ) ;
1114 cmd. env_remove ( "PAGER" ) ;
@@ -17,7 +20,11 @@ fn bat_with_config() -> Command {
1720 cmd
1821}
1922
20- fn bat ( ) -> Command {
23+ fn bat_with_config ( ) -> assert_cmd:: Command {
24+ assert_cmd:: Command :: from_std ( bat_as_std ( ) )
25+ }
26+
27+ fn bat ( ) -> assert_cmd:: Command {
2128 let mut cmd = bat_with_config ( ) ;
2229 cmd. arg ( "--no-config" ) ;
2330 cmd
@@ -189,6 +196,30 @@ fn line_range_multiple() {
189196 . stdout ( "line 1\n line 2\n line 4\n " ) ;
190197}
191198
199+ #[ test]
200+ fn basic_io_cycle ( ) {
201+ let file_out = Stdio :: from ( File :: open ( "tests/examples/cycle.txt" ) . unwrap ( ) ) ;
202+ bat_as_std ( )
203+ . arg ( "test.txt" )
204+ . arg ( "cycle.txt" )
205+ . stdout ( file_out)
206+ . assert ( )
207+ . failure ( ) ;
208+ }
209+
210+ #[ test]
211+ fn stdin_to_stdout_cycle ( ) {
212+ let file_out = Stdio :: from ( File :: open ( "tests/examples/cycle.txt" ) . unwrap ( ) ) ;
213+ let file_in = Stdio :: from ( File :: open ( "tests/examples/cycle.txt" ) . unwrap ( ) ) ;
214+ bat_as_std ( )
215+ . stdin ( file_in)
216+ . arg ( "test.txt" )
217+ . arg ( "-" )
218+ . stdout ( file_out)
219+ . assert ( )
220+ . failure ( ) ;
221+ }
222+
192223#[ test]
193224fn tabs_numbers ( ) {
194225 bat ( )
You can’t perform that action at this time.
0 commit comments