@@ -57,30 +57,35 @@ pub struct Entry {
5757}
5858
5959impl Entry {
60- /// Create an Entry from arguments or as a command string .
61- pub fn new (
60+ /// Create an Entry with the arguments field populated .
61+ pub fn with_arguments (
6262 file : impl Into < path:: PathBuf > ,
6363 arguments : Vec < String > ,
6464 directory : impl Into < path:: PathBuf > ,
6565 output : Option < impl Into < path:: PathBuf > > ,
66- as_array : bool ,
6766 ) -> Self {
68- if as_array {
69- Entry {
70- file : file. into ( ) ,
71- arguments,
72- command : String :: default ( ) ,
73- directory : directory. into ( ) ,
74- output : output. map ( |o| o. into ( ) ) ,
75- }
76- } else {
77- Entry {
78- file : file. into ( ) ,
79- arguments : Vec :: default ( ) ,
80- command : shell_words:: join ( & arguments) ,
81- directory : directory. into ( ) ,
82- output : output. map ( |o| o. into ( ) ) ,
83- }
67+ Entry {
68+ file : file. into ( ) ,
69+ arguments,
70+ command : String :: default ( ) ,
71+ directory : directory. into ( ) ,
72+ output : output. map ( |o| o. into ( ) ) ,
73+ }
74+ }
75+
76+ /// Create an Entry with the command field populated.
77+ pub fn with_command (
78+ file : impl Into < path:: PathBuf > ,
79+ arguments : Vec < String > ,
80+ directory : impl Into < path:: PathBuf > ,
81+ output : Option < impl Into < path:: PathBuf > > ,
82+ ) -> Self {
83+ Entry {
84+ file : file. into ( ) ,
85+ arguments : Vec :: default ( ) ,
86+ command : shell_words:: join ( & arguments) ,
87+ directory : directory. into ( ) ,
88+ output : output. map ( |o| o. into ( ) ) ,
8489 }
8590 }
8691
@@ -221,4 +226,39 @@ mod tests {
221226 assert_eq ! ( err, expected_error) ;
222227 }
223228 }
229+
230+ #[ test]
231+ fn test_entry_with_arguments_constructor ( ) {
232+ let entry = Entry :: with_arguments (
233+ "main.cpp" ,
234+ vec ! [ "clang" . to_string( ) , "-c" . to_string( ) ] ,
235+ "/tmp" ,
236+ Some ( "main.o" ) ,
237+ ) ;
238+
239+ assert ! ( !entry. arguments. is_empty( ) ) ;
240+ assert ! ( entry. command. is_empty( ) ) ;
241+ assert_eq ! ( entry. file, std:: path:: PathBuf :: from( "main.cpp" ) ) ;
242+ assert_eq ! ( entry. directory, std:: path:: PathBuf :: from( "/tmp" ) ) ;
243+ assert_eq ! ( entry. output, Some ( std:: path:: PathBuf :: from( "main.o" ) ) ) ;
244+ assert ! ( entry. validate( ) . is_ok( ) ) ;
245+ }
246+
247+ #[ test]
248+ fn test_entry_with_command_constructor ( ) {
249+ let entry = Entry :: with_command (
250+ "main.cpp" ,
251+ vec ! [ "clang" . to_string( ) , "-c" . to_string( ) ] ,
252+ "/tmp" ,
253+ Some ( "main.o" ) ,
254+ ) ;
255+
256+ assert ! ( entry. arguments. is_empty( ) ) ;
257+ assert ! ( !entry. command. is_empty( ) ) ;
258+ assert_eq ! ( entry. command, "clang -c" ) ;
259+ assert_eq ! ( entry. file, std:: path:: PathBuf :: from( "main.cpp" ) ) ;
260+ assert_eq ! ( entry. directory, std:: path:: PathBuf :: from( "/tmp" ) ) ;
261+ assert_eq ! ( entry. output, Some ( std:: path:: PathBuf :: from( "main.o" ) ) ) ;
262+ assert ! ( entry. validate( ) . is_ok( ) ) ;
263+ }
224264}
0 commit comments