@@ -11,24 +11,35 @@ use diff;
1111pub struct OutputAssertion < T > {
1212 pub expect : String ,
1313 pub fuzzy : bool ,
14+ pub expected_result : bool ,
1415 pub kind : T ,
1516}
1617
1718impl < T : OutputType > OutputAssertion < T > {
1819 fn matches_fuzzy ( & self , got : & str ) -> Result < ( ) > {
19- if !got. contains ( & self . expect ) {
20- bail ! ( ErrorKind :: OutputMismatch ( self . expect. clone( ) , got. into( ) ) ) ;
20+ let result = got. contains ( & self . expect ) ;
21+ if result != self . expected_result {
22+ if self . expected_result {
23+ bail ! ( ErrorKind :: OutputDoesntContain ( self . expect. clone( ) , got. into( ) ) ) ;
24+ } else {
25+ bail ! ( ErrorKind :: OutputContains ( self . expect. clone( ) , got. into( ) ) ) ;
26+ }
2127 }
2228
2329 Ok ( ( ) )
2430 }
2531
2632 fn matches_exact ( & self , got : & str ) -> Result < ( ) > {
2733 let differences = Changeset :: new ( self . expect . trim ( ) , got. trim ( ) , "\n " ) ;
28-
29- if differences. distance > 0 {
30- let nice_diff = diff:: render ( & differences) ?;
31- bail ! ( ErrorKind :: ExactOutputMismatch ( nice_diff) ) ;
34+ let result = differences. distance == 0 ;
35+
36+ if result != self . expected_result {
37+ if self . expected_result {
38+ let nice_diff = diff:: render ( & differences) ?;
39+ bail ! ( ErrorKind :: OutputDoesntMatch ( nice_diff) ) ;
40+ } else {
41+ bail ! ( ErrorKind :: OutputMatches ( got. to_owned( ) ) ) ;
42+ }
3243 }
3344
3445 Ok ( ( ) )
@@ -88,14 +99,22 @@ mod errors {
8899 Fmt ( :: std:: fmt:: Error ) ;
89100 }
90101 errors {
91- OutputMismatch ( expected: String , got: String ) {
102+ OutputDoesntContain ( expected: String , got: String ) {
92103 description( "Output was not as expected" )
93104 display( "expected to contain {:?}, got {:?}" , expected, got)
94105 }
95- ExactOutputMismatch ( diff: String ) {
106+ OutputContains ( expected: String , got: String ) {
107+ description( "Output was not as expected" )
108+ display( "expected to not contain {:?}, got {:?}" , expected, got)
109+ }
110+ OutputDoesntMatch ( diff: String ) {
96111 description( "Output was not as expected" )
97112 display( "{}" , diff)
98113 }
114+ OutputMatches ( got: String ) {
115+ description( "Output was not as expected" )
116+ display( "{}" , got)
117+ }
99118 }
100119 }
101120}
0 commit comments