File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -80,4 +80,35 @@ mod test {
8080 assert_eq ! ( exit_code, 1 ) ;
8181 Ok ( ( ) )
8282 }
83+
84+ mod cq {
85+ use super :: * ;
86+
87+ fn run_cq ( data : & RpcValue , filter : & str ) -> Result < RpcValue , String > {
88+ let block = data. to_chainpack ( ) ;
89+ let mut cmd = Command :: new ( cargo_bin ! ( "cp2cp" ) ) ;
90+ cmd. stdin ( Stdio :: piped ( ) )
91+ . stdout ( Stdio :: piped ( ) )
92+ . stderr ( Stdio :: piped ( ) )
93+ . arg ( "--oc" )
94+ . arg ( "--cq" ) . arg ( filter) ;
95+ let mut child = cmd. spawn ( ) . map_err ( |e| e. to_string ( ) ) ?;
96+ let mut stdin = child. stdin . take ( ) . expect ( "cp2cp should be running" ) ;
97+ thread:: spawn ( move || {
98+ stdin. write_all ( & block) . expect ( "Failed to write to stdin" ) ;
99+ } ) ;
100+ child. wait_with_output ( ) . map_err ( |err| err. to_string ( ) ) . and_then ( |output| {
101+ RpcValue :: from_chainpack ( output. stdout ) . map_err ( |err| err. to_string ( ) )
102+ } )
103+ }
104+
105+ #[ test]
106+ fn dot_filter ( ) -> Result < ( ) , String > {
107+ // <T:RpcMessage,id:4,method:"ls">i{}
108+ let input = RpcValue :: from_cpon ( r#"{"foo": true}"# ) . unwrap ( ) ;
109+ let output = run_cq ( & input, "." ) ?;
110+ assert_eq ! ( input, output) ;
111+ Ok ( ( ) )
112+ }
113+ }
83114}
You can’t perform that action at this time.
0 commit comments