@@ -15,7 +15,12 @@ pub trait CommandRunExt {
15
15
/// Execute the child process.
16
16
fn run ( & mut self ) -> Result < ( ) > ;
17
17
18
- /// Execute the child process, parsing its stdout as JSON.
18
+ /// Execute the child process and capture its output. This uses `run` internally
19
+ /// and will return an error if the child process exits abnormally.
20
+ fn run_get_output ( & mut self ) -> Result < Box < dyn std:: io:: BufRead > > ;
21
+
22
+ /// Execute the child process, parsing its stdout as JSON. This uses `run` internally
23
+ /// and will return an error if the child process exits abnormally.
19
24
fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > ;
20
25
}
21
26
@@ -88,14 +93,18 @@ impl CommandRunExt for Command {
88
93
self
89
94
}
90
95
91
- /// Synchronously execute the child, and parse its stdout as JSON.
92
- fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > {
96
+ fn run_get_output ( & mut self ) -> Result < Box < dyn std:: io:: BufRead > > {
93
97
let mut stdout = tempfile:: tempfile ( ) ?;
94
98
self . stdout ( stdout. try_clone ( ) ?) ;
95
99
self . run ( ) ?;
96
100
stdout. seek ( std:: io:: SeekFrom :: Start ( 0 ) ) . context ( "seek" ) ?;
97
- let stdout = std:: io:: BufReader :: new ( stdout) ;
98
- serde_json:: from_reader ( stdout) . map_err ( Into :: into)
101
+ Ok ( Box :: new ( std:: io:: BufReader :: new ( stdout) ) )
102
+ }
103
+
104
+ /// Synchronously execute the child, and parse its stdout as JSON.
105
+ fn run_and_parse_json < T : serde:: de:: DeserializeOwned > ( & mut self ) -> Result < T > {
106
+ let output = self . run_get_output ( ) ?;
107
+ serde_json:: from_reader ( output) . map_err ( Into :: into)
99
108
}
100
109
}
101
110
0 commit comments