@@ -44,6 +44,7 @@ impl Temp {
4444}
4545
4646impl Drop for Temp {
47+ /// Delete the created temporary directory.
4748 fn drop ( & mut self ) {
4849 let path = & self . 0 ;
4950 if let Err ( error) = remove_dir_all ( path) {
@@ -57,6 +58,7 @@ impl Drop for Temp {
5758pub struct SampleWorkspace ( Temp ) ;
5859
5960impl Default for SampleWorkspace {
61+ /// Set up a temporary directory for tests.
6062 fn default ( ) -> Self {
6163 let temp = Temp :: new_dir ( ) . expect ( "create working directory for sample workspace" ) ;
6264
@@ -208,22 +210,26 @@ where
208210/// Path to the `pdu` executable
209211pub const PDU : & str = env ! ( "CARGO_BIN_EXE_pdu" ) ;
210212
213+ /// Representation of a `pdu` command.
211214#[ derive( Debug , Default , Clone ) ]
212215pub struct CommandRepresentation < ' a > {
213216 args : Vec < & ' a str > ,
214217}
215218
216219impl < ' a > CommandRepresentation < ' a > {
220+ /// Add an argument.
217221 pub fn arg ( mut self , arg : & ' a str ) -> Self {
218222 self . args . push ( arg) ;
219223 self
220224 }
221225}
222226
227+ /// List of `pdu` commands.
223228#[ derive( Debug , Clone , AsRef , Deref ) ]
224229pub struct CommandList < ' a > ( Vec < CommandRepresentation < ' a > > ) ;
225230
226231impl < ' a > Default for CommandList < ' a > {
232+ /// Initialize a list with one `pdu` command.
227233 fn default ( ) -> Self {
228234 CommandRepresentation :: default ( )
229235 . pipe ( |x| vec ! [ x] )
@@ -232,6 +238,10 @@ impl<'a> Default for CommandList<'a> {
232238}
233239
234240impl < ' a > CommandList < ' a > {
241+ /// Duplicate the list with a flag argument.
242+ ///
243+ /// The resulting list would include the original list with the flag
244+ /// followed by the original list without the flag.
235245 pub fn flag_matrix ( self , name : & ' a str ) -> Self {
236246 Self :: assert_flag ( name) ;
237247 let CommandList ( list) = self ;
@@ -243,6 +253,10 @@ impl<'a> CommandList<'a> {
243253 . pipe ( CommandList )
244254 }
245255
256+ /// Duplicate the list with one or many option argument(s).
257+ ///
258+ /// The resulting list would include the original list with the option(s)
259+ /// followed by the original list without the option(s).
246260 pub fn option_matrix < const LEN : usize > ( self , name : & ' a str , values : [ & ' a str ; LEN ] ) -> Self {
247261 Self :: assert_flag ( name) ;
248262 let CommandList ( tail) = self ;
@@ -259,11 +273,13 @@ impl<'a> CommandList<'a> {
259273 CommandList ( head)
260274 }
261275
276+ /// Create a list of `pdu` [command](Command).
262277 pub fn commands ( & ' a self ) -> impl Iterator < Item = Command > + ' a {
263278 self . iter ( )
264279 . map ( |cmd| Command :: new ( PDU ) . with_args ( & cmd. args ) )
265280 }
266281
282+ /// Make sure a flag name has valid syntax.
267283 fn assert_flag ( name : & str ) {
268284 match name. len ( ) {
269285 0 | 1 => panic ! ( "{:?} is not a valid flag" , name) ,
@@ -273,6 +289,8 @@ impl<'a> CommandList<'a> {
273289 }
274290}
275291
292+ /// Make sure that status code is 0, print stderr if it's not empty,
293+ /// and turn stdin into a string.
276294pub fn stdout_text (
277295 Output {
278296 status,
@@ -293,6 +311,7 @@ pub fn stdout_text(
293311 . to_string ( )
294312}
295313
314+ /// Print stderr if it's not empty.
296315pub fn inspect_stderr ( stderr : & [ u8 ] ) {
297316 let text = String :: from_utf8_lossy ( stderr) ;
298317 let text = text. trim ( ) ;
0 commit comments