1- use assert_cmd:: prelude :: * ;
1+ use assert_cmd:: cargo ;
22use insta:: Settings ;
3- use insta_cmd :: assert_cmd_snapshot ;
3+ use insta :: assert_snapshot ;
44use serial_test:: serial;
5- use std:: { path:: Path , process :: Command } ;
5+ use std:: path:: Path ;
66
77fn standard_filter ( ) -> Settings {
88 let mut settings = insta:: Settings :: clone_current ( ) ;
@@ -19,10 +19,29 @@ fn standard_filter() -> Settings {
1919 settings
2020}
2121
22+ fn mimic_insta_snapshot (
23+ output : std:: process:: Output ,
24+ ) -> Result < String , Box < dyn std:: error:: Error > > {
25+ let success = output. status . success ( ) ;
26+ let exit_code = output. status . code ( ) . unwrap ( ) ;
27+ let stdout = str:: from_utf8 ( & output. stdout ) ?;
28+ let stderr = str:: from_utf8 ( & output. stderr ) ?;
29+ Ok ( format ! (
30+ r#"
31+ success: {success}
32+ exit_code: {exit_code}
33+ ----- stdout -----
34+ {stdout}
35+ ----- stderr -----
36+ {stderr}
37+ "#
38+ ) )
39+ }
40+
2241#[ test]
2342#[ serial]
2443fn show_corpus_info ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
25- let mut cmd = Command :: cargo_bin ( "annis" ) ? ;
44+ let mut cmd = cargo :: cargo_bin_cmd! ( "annis" ) ;
2645
2746 cmd. arg ( "../graphannis/tests/data/" )
2847 . arg ( "-c" )
@@ -32,29 +51,33 @@ fn show_corpus_info() -> Result<(), Box<dyn std::error::Error>> {
3251 . arg ( "-c" )
3352 . arg ( "info" ) ;
3453
54+ let output = cmd. output ( ) . unwrap ( ) ;
55+ let actual = mimic_insta_snapshot ( output) ?;
3556 let settings = standard_filter ( ) ;
36- settings. bind ( || assert_cmd_snapshot ! ( cmd ) ) ;
57+ settings. bind ( || assert_snapshot ! ( actual ) ) ;
3758
3859 Ok ( ( ) )
3960}
4061
4162#[ test]
4263#[ serial]
4364fn list_corpora_not_loaded ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
44- let mut cmd = Command :: cargo_bin ( "annis" ) ? ;
65+ let mut cmd = cargo :: cargo_bin_cmd! ( "annis" ) ;
4566
4667 cmd. arg ( "../graphannis/tests/data/" ) . arg ( "-c" ) . arg ( "list" ) ;
4768
69+ let output = cmd. output ( ) . unwrap ( ) ;
70+ let actual = mimic_insta_snapshot ( output) ?;
4871 let settings = standard_filter ( ) ;
49- settings. bind ( || assert_cmd_snapshot ! ( cmd ) ) ;
72+ settings. bind ( || assert_snapshot ! ( actual ) ) ;
5073
5174 Ok ( ( ) )
5275}
5376
5477#[ test]
5578#[ serial]
5679fn list_corpora_fully_loaded ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
57- let mut cmd = Command :: cargo_bin ( "annis" ) ? ;
80+ let mut cmd = cargo :: cargo_bin_cmd! ( "annis" ) ;
5881
5982 cmd. arg ( "../graphannis/tests/data/" )
6083 . arg ( "-c" )
@@ -64,16 +87,18 @@ fn list_corpora_fully_loaded() -> Result<(), Box<dyn std::error::Error>> {
6487 . arg ( "-c" )
6588 . arg ( "list" ) ;
6689
90+ let output = cmd. output ( ) . unwrap ( ) ;
91+ let actual = mimic_insta_snapshot ( output) ?;
6792 let settings = standard_filter ( ) ;
68- settings. bind ( || assert_cmd_snapshot ! ( cmd ) ) ;
93+ settings. bind ( || assert_snapshot ! ( actual ) ) ;
6994
7095 Ok ( ( ) )
7196}
7297
7398#[ test]
7499#[ serial]
75100fn list_corpora_partially_loaded ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
76- let mut cmd = Command :: cargo_bin ( "annis" ) ? ;
101+ let mut cmd = cargo :: cargo_bin_cmd! ( "annis" ) ;
77102
78103 cmd. arg ( "../graphannis/tests/data/" )
79104 . arg ( "-c" )
@@ -83,25 +108,29 @@ fn list_corpora_partially_loaded() -> Result<(), Box<dyn std::error::Error>> {
83108 . arg ( "-c" )
84109 . arg ( "list" ) ;
85110
111+ let output = cmd. output ( ) . unwrap ( ) ;
112+ let actual = mimic_insta_snapshot ( output) ?;
86113 let settings = standard_filter ( ) ;
87- settings. bind ( || assert_cmd_snapshot ! ( cmd ) ) ;
114+ settings. bind ( || assert_snapshot ! ( actual ) ) ;
88115
89116 Ok ( ( ) )
90117}
91118
92119#[ test]
93120#[ serial]
94121fn export_to_zip_file ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
95- let mut cmd = Command :: cargo_bin ( "annis" ) ? ;
122+ let mut cmd = cargo :: cargo_bin_cmd! ( "annis" ) ;
96123
97124 cmd. arg ( "../graphannis/tests/data/" )
98125 . arg ( "-c" )
99126 . arg ( "corpus sample-disk-based-3.3" )
100127 . arg ( "-c" )
101128 . arg ( "export sample-disk-based-3.3.zip" ) ;
102129
130+ let output = cmd. output ( ) . unwrap ( ) ;
131+ let actual = mimic_insta_snapshot ( output) ?;
103132 let settings = standard_filter ( ) ;
104- settings. bind ( || assert_cmd_snapshot ! ( cmd ) ) ;
133+ settings. bind ( || assert_snapshot ! ( actual ) ) ;
105134
106135 // Check that the file has been created
107136 let p = Path :: new ( "sample-disk-based-3.3.zip" ) ;
0 commit comments