@@ -153,6 +153,13 @@ impl Assert {
153
153
/// .stdout().is("FOO=BAR")
154
154
/// .execute()
155
155
/// .unwrap();
156
+ ///
157
+ /// ::std::env::set_var("BAZ", "BAR");
158
+ ///
159
+ /// assert_cli::Assert::command(&["printenv"])
160
+ /// .stdout().contains("BAZ=BAR")
161
+ /// .execute()
162
+ /// .unwrap();
156
163
/// ```
157
164
pub fn with_env < E : Into < Environment > > ( mut self , env : E ) -> Self {
158
165
self . env = env. into ( ) ;
@@ -495,14 +502,12 @@ mod test {
495
502
fn in_place_mod2 ( ) {
496
503
let x = Environment :: inherit ( ) ;
497
504
498
- assert ! (
499
- command( )
500
- . with_env( & x. insert( "key" , "value" ) . insert( "key" , "vv" ) )
501
- . stdout( )
502
- . contains( "key=vv" )
503
- . execute( )
504
- . is_ok( )
505
- ) ;
505
+ command ( )
506
+ . with_env ( & x. insert ( "key" , "value" ) . insert ( "key" , "vv" ) )
507
+ . stdout ( )
508
+ . contains ( "key=vv" )
509
+ . execute ( )
510
+ . unwrap ( ) ;
506
511
// Granted, `insert` moved `x`, so we can no longer reference it, even
507
512
// though only a reference was passed to `with_env`
508
513
}
@@ -517,15 +522,13 @@ mod test {
517
522
vec![ ( OsString :: from( "key" ) , OsString :: from( "value" ) ) ]
518
523
) ;
519
524
520
- assert ! (
521
- command( )
522
- . with_env( y)
523
- . stdout( )
524
- . not( )
525
- . contains( "key=value" )
526
- . execute( )
527
- . is_ok( )
528
- ) ;
525
+ command ( )
526
+ . with_env ( y)
527
+ . stdout ( )
528
+ . not ( )
529
+ . contains ( "key=value" )
530
+ . execute ( )
531
+ . unwrap ( ) ;
529
532
}
530
533
531
534
#[ test]
@@ -539,117 +542,95 @@ mod test {
539
542
fn take_vec ( ) {
540
543
let v = vec ! [ ( "bar" . to_string( ) , "baz" . to_string( ) ) ] ;
541
544
542
- assert ! (
543
- command( )
544
- . with_env( & vec![ ( "bar" , "baz" ) ] )
545
- . stdout( )
546
- . contains( "bar=baz" )
547
- . execute( )
548
- . is_ok( )
549
- ) ;
545
+ command ( )
546
+ . with_env ( & vec ! [ ( "bar" , "baz" ) ] )
547
+ . stdout ( )
548
+ . contains ( "bar=baz" )
549
+ . execute ( )
550
+ . unwrap ( ) ;
550
551
551
- assert ! (
552
- command( )
553
- . with_env( & v)
554
- . stdout( )
555
- . contains( "bar=baz" )
556
- . execute( )
557
- . is_ok( )
558
- ) ;
552
+ command ( )
553
+ . with_env ( & v)
554
+ . stdout ( )
555
+ . contains ( "bar=baz" )
556
+ . execute ( )
557
+ . unwrap ( ) ;
559
558
560
- assert ! (
561
- command( )
562
- . with_env( & vec![ ( "bar" , "baz" ) ] )
563
- . stdout( )
564
- . isnt( "" )
565
- . execute( )
566
- . is_ok( )
567
- ) ;
559
+ command ( )
560
+ . with_env ( & vec ! [ ( "bar" , "baz" ) ] )
561
+ . stdout ( )
562
+ . isnt ( "" )
563
+ . execute ( )
564
+ . unwrap ( ) ;
568
565
}
569
566
570
567
#[ test]
571
568
fn take_slice_of_strs ( ) {
572
- assert ! (
573
- command( )
574
- . with_env( & [ ( "bar" , "BAZ" ) ] )
575
- . stdout( )
576
- . contains( "bar=BAZ" )
577
- . execute( )
578
- . is_ok( )
579
- ) ;
580
-
581
- assert ! (
582
- command( )
583
- . with_env( & [ ( "bar" , "BAZ" ) ] [ ..] )
584
- . stdout( )
585
- . contains( "bar=BAZ" )
586
- . execute( )
587
- . is_ok( )
588
- ) ;
589
-
590
- assert ! (
591
- command( )
592
- . with_env( [ ( "bar" , "BAZ" ) ] . as_ref( ) )
593
- . stdout( )
594
- . contains( "bar=BAZ" )
595
- . execute( )
596
- . is_ok( )
597
- ) ;
569
+ command ( )
570
+ . with_env ( & [ ( "bar" , "BAZ" ) ] )
571
+ . stdout ( )
572
+ . contains ( "bar=BAZ" )
573
+ . execute ( )
574
+ . unwrap ( ) ;
575
+
576
+ command ( )
577
+ . with_env ( & [ ( "bar" , "BAZ" ) ] [ ..] )
578
+ . stdout ( )
579
+ . contains ( "bar=BAZ" )
580
+ . execute ( )
581
+ . unwrap ( ) ;
582
+
583
+ command ( )
584
+ . with_env ( [ ( "bar" , "BAZ" ) ] . as_ref ( ) )
585
+ . stdout ( )
586
+ . contains ( "bar=BAZ" )
587
+ . execute ( )
588
+ . unwrap ( ) ;
598
589
}
599
590
600
591
#[ test]
601
592
fn take_slice_of_strings ( ) {
602
593
// same deal as above
603
594
604
- assert ! (
605
- command( )
606
- . with_env( & [ ( "bar" . to_string( ) , "BAZ" . to_string( ) ) ] )
607
- . stdout( )
608
- . contains( "bar=BAZ" )
609
- . execute( )
610
- . is_ok( )
611
- ) ;
595
+ command ( )
596
+ . with_env ( & [ ( "bar" . to_string ( ) , "BAZ" . to_string ( ) ) ] )
597
+ . stdout ( )
598
+ . contains ( "bar=BAZ" )
599
+ . execute ( )
600
+ . unwrap ( ) ;
612
601
613
- assert ! (
614
- command( )
615
- . with_env( & [ ( "bar" . to_string( ) , "BAZ" . to_string( ) ) ] [ ..] )
616
- . stdout( )
617
- . contains( "bar=BAZ" )
618
- . execute( )
619
- . is_ok( )
620
- ) ;
602
+ command ( )
603
+ . with_env ( & [ ( "bar" . to_string ( ) , "BAZ" . to_string ( ) ) ] [ ..] )
604
+ . stdout ( )
605
+ . contains ( "bar=BAZ" )
606
+ . execute ( )
607
+ . unwrap ( ) ;
621
608
}
622
609
623
610
#[ test]
624
611
fn take_slice ( ) {
625
- assert ! (
626
- command( )
627
- . with_env( & [ ( "hey" , "ho" ) ] )
628
- . stdout( )
629
- . contains( "hey=ho" )
630
- . execute( )
631
- . is_ok( )
632
- ) ;
612
+ command ( )
613
+ . with_env ( & [ ( "hey" , "ho" ) ] )
614
+ . stdout ( )
615
+ . contains ( "hey=ho" )
616
+ . execute ( )
617
+ . unwrap ( ) ;
633
618
634
- assert ! (
635
- command( )
636
- . with_env( & [ ( "hey" , "ho" . to_string( ) ) ] )
637
- . stdout( )
638
- . contains( "hey=ho" )
639
- . execute( )
640
- . is_ok( )
641
- ) ;
619
+ command ( )
620
+ . with_env ( & [ ( "hey" , "ho" . to_string ( ) ) ] )
621
+ . stdout ( )
622
+ . contains ( "hey=ho" )
623
+ . execute ( )
624
+ . unwrap ( ) ;
642
625
}
643
626
644
627
#[ test]
645
628
fn take_string_i32 ( ) {
646
- assert ! (
647
- command( )
648
- . with_env( & [ ( "bar" , 3 as i32 ) ] )
649
- . stdout( )
650
- . contains( "bar=3" )
651
- . execute( )
652
- . is_ok( )
653
- ) ;
629
+ command ( )
630
+ . with_env ( & [ ( "bar" , 3 as i32 ) ] )
631
+ . stdout ( )
632
+ . contains ( "bar=3" )
633
+ . execute ( )
634
+ . unwrap ( ) ;
654
635
}
655
636
}
0 commit comments