1
1
use crate :: app:: load_config:: load_config;
2
- use crate :: app:: requirements_validate :: get_requirements_from_files;
2
+ use crate :: app:: requirements :: get_requirements_from_files;
3
3
use crate :: app:: {
4
- init_config :: init_config ,
5
- requirements_validate :: {
4
+ init_workspace :: init_workspace ,
5
+ requirements :: {
6
6
get_requirements_from_file, validate_requirements_file, validate_requirements_files,
7
7
} ,
8
8
} ;
9
- use crate :: types:: RequirementsFile ;
10
- use common:: types:: Requirement ;
9
+ use crate :: types:: { RequirementsFile , TestCasesBuilderFile } ;
11
10
12
11
use std:: path:: PathBuf ;
13
12
14
13
use anyhow:: { Context , Ok , Result } ;
15
14
use clap:: { Parser , Subcommand } ;
16
15
17
- use super :: requirements_validate :: get_requirements_files;
16
+ use super :: requirements :: get_requirements_files;
18
17
19
18
// Define the main application
20
19
#[ derive( Parser ) ]
@@ -27,9 +26,9 @@ struct App {
27
26
// Define the top-level subcommands
28
27
#[ derive( Subcommand ) ]
29
28
enum Commands {
30
- /// Create a directory to start working from
29
+ /// Create a new YATM workspace
31
30
Init {
32
- /// The path to the project
31
+ /// The path to the new workspace
33
32
#[ clap( short, long) ]
34
33
path : PathBuf ,
35
34
} ,
@@ -91,6 +90,14 @@ struct Subcommand1Options {
91
90
92
91
#[ derive( Subcommand ) ]
93
92
enum TestCasesSubcommands {
93
+ /// Create a new test case builder
94
+ New {
95
+ /// The path to the project
96
+ #[ clap( short, long, default_value = "." ) ]
97
+ config_path : PathBuf ,
98
+ #[ clap( short, long) ]
99
+ file_name : Option < String > ,
100
+ } ,
94
101
/// Check the test cases
95
102
Validate ,
96
103
/// List the test cases
@@ -113,8 +120,8 @@ pub fn cli() -> Result<()> {
113
120
let app = App :: parse ( ) ;
114
121
match app. command {
115
122
Commands :: Init { path } => {
116
- init_config ( & path) ?;
117
- println ! ( "Created the project in {:?}" , path) ;
123
+ init_workspace ( & path) ?;
124
+ println ! ( "Created a YATM workspace in {:?}" , path) ;
118
125
}
119
126
Commands :: Requirements { subcommand } => match subcommand {
120
127
RequirementsSubcommands :: New {
@@ -133,10 +140,7 @@ pub fn cli() -> Result<()> {
133
140
}
134
141
} ;
135
142
136
- if config. requirements_dirs . len ( ) < 1 {
137
- anyhow:: bail!( "No requirements directories found" ) ;
138
- }
139
- let requirements_file_path = config. requirements_dirs [ 0 ] . join ( file_name) ;
143
+ let requirements_file_path = config. new_requirements_dir . join ( file_name) ;
140
144
if requirements_file_path. exists ( ) {
141
145
anyhow:: bail!(
142
146
"The requirements file already exists: {:?}" ,
@@ -187,6 +191,44 @@ pub fn cli() -> Result<()> {
187
191
}
188
192
} ,
189
193
Commands :: TestCases { subcommand } => match subcommand {
194
+ TestCasesSubcommands :: New {
195
+ config_path,
196
+ file_name,
197
+ } => {
198
+ let config = load_config ( & config_path) ?;
199
+
200
+ let file_name = match file_name {
201
+ Some ( file_name) => file_name,
202
+ None => {
203
+ // get datetime string in current timezone
204
+ let datetime_string =
205
+ chrono:: Local :: now ( ) . format ( "%Y-%m-%d-%H-%M-%S" ) . to_string ( ) ;
206
+ format ! ( "test_cases_builder-{}.yaml" , datetime_string)
207
+ }
208
+ } ;
209
+
210
+ let test_cases_builder_file_path =
211
+ config. new_test_cases_builder_dir . join ( file_name) ;
212
+ if test_cases_builder_file_path. exists ( ) {
213
+ anyhow:: bail!(
214
+ "The test cases builder file already exists: {:?}" ,
215
+ test_cases_builder_file_path
216
+ ) ;
217
+ }
218
+ let test_cases_builder_file = TestCasesBuilderFile :: default ( ) ;
219
+ let test_cases_builder_file = serde_yaml:: to_string ( & test_cases_builder_file)
220
+ . context ( "Failed to turn test cases builder file into a string" ) ?;
221
+ std:: fs:: write ( & test_cases_builder_file_path, test_cases_builder_file) . context (
222
+ format ! (
223
+ "Failed to write the test cases builder file: {:?}" ,
224
+ test_cases_builder_file_path
225
+ ) ,
226
+ ) ?;
227
+ println ! (
228
+ "Created the test cases builder file: {:?}" ,
229
+ test_cases_builder_file_path
230
+ ) ;
231
+ }
190
232
TestCasesSubcommands :: Validate => {
191
233
println ! ( "Running validate" ) ;
192
234
}
@@ -220,6 +262,8 @@ mod test_cli {
220
262
use predicates:: prelude:: predicate;
221
263
use tempfile:: tempdir;
222
264
265
+ use crate :: app:: load_config:: load_config;
266
+
223
267
fn get_command ( ) -> Command {
224
268
Command :: cargo_bin ( env ! ( "CARGO_PKG_NAME" ) ) . unwrap ( )
225
269
}
@@ -249,15 +293,18 @@ mod test_cli {
249
293
cmd. args ( & [ "init" , "--path" , dir. to_str ( ) . unwrap ( ) ] )
250
294
. assert ( )
251
295
. success ( )
252
- . stdout ( predicate:: str:: contains ( "Created the project in" ) ) ;
296
+ . stdout ( predicate:: str:: contains ( "Created a YATM workspace in" ) ) ;
253
297
254
- // check that files are generated correctly
298
+ // load the config
255
299
assert ! ( dir. join( "config.yaml" ) . is_file( ) ) ;
256
- assert ! ( dir. join( ".generated_files" ) . is_dir( ) ) ;
300
+ let config = load_config ( & dir) . unwrap ( ) ;
301
+
302
+ // check that files are generated correctly
303
+ assert ! ( config. new_requirements_dir. is_dir( ) ) ;
304
+ assert ! ( config. new_test_cases_builder_dir. is_dir( ) ) ;
305
+ assert ! ( config. generated_files_dir. is_dir( ) ) ;
257
306
assert ! ( dir. join( ".gitignore" ) . is_file( ) ) ;
258
- let requirements_dir = dir. join ( "requirements" ) ;
259
- assert ! ( requirements_dir. is_dir( ) ) ;
260
- assert_eq ! ( get_number_of_files_in_dir( & requirements_dir) , 1 ) ;
307
+ assert_eq ! ( get_number_of_files_in_dir( & config. new_requirements_dir) , 1 ) ;
261
308
262
309
// run the requirements new command
263
310
let new_requirements_file_name = "my-test-requirements.yaml" ;
@@ -272,9 +319,10 @@ mod test_cli {
272
319
] )
273
320
. assert ( )
274
321
. success ( ) ;
275
- let new_requirements_file_path = requirements_dir. join ( new_requirements_file_name) ;
322
+ let new_requirements_file_path =
323
+ config. new_requirements_dir . join ( new_requirements_file_name) ;
276
324
assert ! ( new_requirements_file_path. is_file( ) ) ;
277
- assert_eq ! ( get_number_of_files_in_dir( & requirements_dir ) , 2 ) ;
325
+ assert_eq ! ( get_number_of_files_in_dir( & config . new_requirements_dir ) , 2 ) ;
278
326
279
327
// run the requirements new command without a file name
280
328
let mut cmd = get_command ( ) ;
@@ -286,7 +334,7 @@ mod test_cli {
286
334
] )
287
335
. assert ( )
288
336
. success ( ) ;
289
- assert_eq ! ( get_number_of_files_in_dir( & requirements_dir ) , 3 ) ;
337
+ assert_eq ! ( get_number_of_files_in_dir( & config . new_requirements_dir ) , 3 ) ;
290
338
291
339
// run the requirements list command
292
340
let mut cmd = get_command ( ) ;
0 commit comments