@@ -36,6 +36,10 @@ pub enum RecordOutput<T: ColumnType> {
36
36
rows : Vec < Vec < String > > ,
37
37
error : Option < AnyError > ,
38
38
} ,
39
+ MultiLineQuery {
40
+ lines : Vec < String > ,
41
+ error : Option < AnyError > ,
42
+ } ,
39
43
/// The output of a `statement`.
40
44
Statement { count : u64 , error : Option < AnyError > } ,
41
45
/// The output of a `system` command.
@@ -52,6 +56,9 @@ pub enum DBOutput<T: ColumnType> {
52
56
types : Vec < T > ,
53
57
rows : Vec < Vec < String > > ,
54
58
} ,
59
+ MultiLine {
60
+ lines : Vec < String > ,
61
+ } ,
55
62
/// A statement in the query has completed.
56
63
///
57
64
/// The number of rows modified or selected is returned.
@@ -293,6 +300,8 @@ pub enum TestErrorKind {
293
300
expected : String ,
294
301
actual : String ,
295
302
} ,
303
+ #[ error( "query result type mismatch:\n [SQL] {sql}\n The query expected {expected} output" ) ]
304
+ QueryResultTypeMismatch { sql : String , expected : String } ,
296
305
#[ error(
297
306
"query columns mismatch:\n [SQL] {sql}\n {}" ,
298
307
format_column_diff( expected, actual, false )
@@ -607,6 +616,9 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
607
616
rows,
608
617
error : None ,
609
618
} ,
619
+ DBOutput :: MultiLine { lines } => {
620
+ RecordOutput :: MultiLineQuery { lines, error : None }
621
+ }
610
622
DBOutput :: StatementComplete ( count) => {
611
623
RecordOutput :: Statement { count, error : None }
612
624
}
@@ -751,6 +763,9 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
751
763
let ( types, mut rows) = match conn. run ( & sql) . await {
752
764
Ok ( out) => match out {
753
765
DBOutput :: Rows { types, rows } => ( types, rows) ,
766
+ DBOutput :: MultiLine { lines } => {
767
+ return RecordOutput :: MultiLineQuery { lines, error : None }
768
+ }
754
769
DBOutput :: StatementComplete ( count) => {
755
770
return RecordOutput :: Statement { count, error : None } ;
756
771
}
@@ -766,6 +781,7 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
766
781
767
782
let sort_mode = match expected {
768
783
QueryExpect :: Results { sort_mode, .. } => sort_mode,
784
+ QueryExpect :: MultiLine { .. } => None ,
769
785
QueryExpect :: Error ( _) => None ,
770
786
}
771
787
. or ( self . sort_mode ) ;
@@ -881,6 +897,14 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
881
897
. at ( loc) )
882
898
}
883
899
QueryExpect :: Results { .. } => { }
900
+ QueryExpect :: MultiLine { data } => {
901
+ return Err ( TestErrorKind :: QueryResultMismatch {
902
+ sql,
903
+ expected : data. join ( "\n " ) ,
904
+ actual : "" . to_string ( ) ,
905
+ }
906
+ . at ( loc) ) ;
907
+ }
884
908
} ,
885
909
(
886
910
Record :: Statement {
@@ -959,6 +983,14 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
959
983
. at ( loc) ) ;
960
984
}
961
985
}
986
+ ( Some ( e) , QueryExpect :: MultiLine { .. } ) => {
987
+ return Err ( TestErrorKind :: Fail {
988
+ sql,
989
+ err : Arc :: clone ( e) ,
990
+ kind : RecordKind :: Query ,
991
+ }
992
+ . at ( loc) )
993
+ }
962
994
( Some ( e) , QueryExpect :: Results { .. } ) => {
963
995
return Err ( TestErrorKind :: Fail {
964
996
sql,
@@ -967,6 +999,13 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
967
999
}
968
1000
. at ( loc) ) ;
969
1001
}
1002
+ ( None , QueryExpect :: MultiLine { .. } ) => {
1003
+ return Err ( TestErrorKind :: QueryResultTypeMismatch {
1004
+ sql,
1005
+ expected : "multiline" . to_string ( ) ,
1006
+ }
1007
+ . at ( loc) ) ;
1008
+ }
970
1009
(
971
1010
None ,
972
1011
QueryExpect :: Results {
@@ -997,6 +1036,72 @@ impl<D: AsyncDB, M: MakeConnection<Conn = D>> Runner<D, M> {
997
1036
}
998
1037
} ;
999
1038
}
1039
+ (
1040
+ Record :: Query {
1041
+ loc,
1042
+ conditions : _,
1043
+ connection : _,
1044
+ sql,
1045
+ expected,
1046
+ } ,
1047
+ RecordOutput :: MultiLineQuery { lines, error } ,
1048
+ ) => {
1049
+ match ( error, expected) {
1050
+ ( None , QueryExpect :: Error ( _) ) => {
1051
+ return Err ( TestErrorKind :: Ok {
1052
+ sql,
1053
+ kind : RecordKind :: Query ,
1054
+ }
1055
+ . at ( loc) ) ;
1056
+ }
1057
+ ( Some ( e) , QueryExpect :: Error ( expected_error) ) => {
1058
+ if !expected_error. is_match ( & e. to_string ( ) ) {
1059
+ return Err ( TestErrorKind :: ErrorMismatch {
1060
+ sql,
1061
+ err : Arc :: clone ( e) ,
1062
+ expected_err : expected_error. to_string ( ) ,
1063
+ kind : RecordKind :: Query ,
1064
+ }
1065
+ . at ( loc) ) ;
1066
+ }
1067
+ }
1068
+ ( Some ( e) , QueryExpect :: MultiLine { .. } ) => {
1069
+ return Err ( TestErrorKind :: Fail {
1070
+ sql,
1071
+ err : Arc :: clone ( e) ,
1072
+ kind : RecordKind :: Query ,
1073
+ }
1074
+ . at ( loc) )
1075
+ }
1076
+ ( Some ( e) , QueryExpect :: Results { .. } ) => {
1077
+ return Err ( TestErrorKind :: Fail {
1078
+ sql,
1079
+ err : Arc :: clone ( e) ,
1080
+ kind : RecordKind :: Query ,
1081
+ }
1082
+ . at ( loc) ) ;
1083
+ }
1084
+ ( None , QueryExpect :: MultiLine { data } ) => {
1085
+ for ( actual, expected) in lines. iter ( ) . zip ( data. iter ( ) ) {
1086
+ if actual != expected {
1087
+ return Err ( TestErrorKind :: QueryResultMismatch {
1088
+ sql,
1089
+ expected : data. join ( "\n " ) ,
1090
+ actual : lines. join ( "\n " ) ,
1091
+ }
1092
+ . at ( loc) ) ;
1093
+ }
1094
+ }
1095
+ }
1096
+ ( None , QueryExpect :: Results { .. } ) => {
1097
+ return Err ( TestErrorKind :: QueryResultTypeMismatch {
1098
+ sql,
1099
+ expected : "result" . to_string ( ) ,
1100
+ }
1101
+ . at ( loc) ) ;
1102
+ }
1103
+ } ;
1104
+ }
1000
1105
(
1001
1106
Record :: System {
1002
1107
loc,
@@ -1481,6 +1586,7 @@ pub fn update_record_with_output<T: ColumnType>(
1481
1586
( Some ( e) , r) => {
1482
1587
let reference = match & r {
1483
1588
QueryExpect :: Error ( e) => Some ( e) ,
1589
+ QueryExpect :: MultiLine { .. } => None ,
1484
1590
QueryExpect :: Results { .. } => None ,
1485
1591
} ;
1486
1592
Some ( Record :: Query {
@@ -1525,6 +1631,12 @@ pub fn update_record_with_output<T: ColumnType>(
1525
1631
sort_mode,
1526
1632
label,
1527
1633
} ,
1634
+ QueryExpect :: MultiLine { .. } => QueryExpect :: Results {
1635
+ results,
1636
+ types,
1637
+ sort_mode : None ,
1638
+ label : None ,
1639
+ } ,
1528
1640
QueryExpect :: Error ( _) => QueryExpect :: Results {
1529
1641
results,
1530
1642
types,
@@ -1535,6 +1647,59 @@ pub fn update_record_with_output<T: ColumnType>(
1535
1647
} )
1536
1648
}
1537
1649
} ,
1650
+ // query, multiline query
1651
+ (
1652
+ Record :: Query {
1653
+ loc,
1654
+ conditions,
1655
+ connection,
1656
+ sql,
1657
+ expected,
1658
+ } ,
1659
+ RecordOutput :: MultiLineQuery { lines, error } ,
1660
+ ) => match ( error, expected) {
1661
+ // Error match
1662
+ ( Some ( e) , QueryExpect :: Error ( expected_error) )
1663
+ if expected_error. is_match ( & e. to_string ( ) ) =>
1664
+ {
1665
+ None
1666
+ }
1667
+ // Error mismatch
1668
+ ( Some ( e) , r) => {
1669
+ let reference = match & r {
1670
+ QueryExpect :: Error ( e) => Some ( e) ,
1671
+ QueryExpect :: MultiLine { .. } => None ,
1672
+ QueryExpect :: Results { .. } => None ,
1673
+ } ;
1674
+ Some ( Record :: Query {
1675
+ sql,
1676
+ expected : QueryExpect :: Error ( ExpectedError :: from_actual_error (
1677
+ reference,
1678
+ & e. to_string ( ) ,
1679
+ ) ) ,
1680
+ loc,
1681
+ conditions,
1682
+ connection,
1683
+ } )
1684
+ }
1685
+ ( None , expected) => Some ( Record :: Query {
1686
+ sql,
1687
+ loc,
1688
+ conditions,
1689
+ connection,
1690
+ expected : match expected {
1691
+ QueryExpect :: Results { .. } => QueryExpect :: MultiLine {
1692
+ data : lines. clone ( ) ,
1693
+ } ,
1694
+ QueryExpect :: MultiLine { .. } => QueryExpect :: MultiLine {
1695
+ data : lines. clone ( ) ,
1696
+ } ,
1697
+ QueryExpect :: Error ( _) => QueryExpect :: MultiLine {
1698
+ data : lines. clone ( ) ,
1699
+ } ,
1700
+ } ,
1701
+ } ) ,
1702
+ } ,
1538
1703
(
1539
1704
Record :: System {
1540
1705
loc,
0 commit comments