sagiegurari / cargo-make
1
use super::*;
2
use crate::types::{CliArgs, GlobalConfig};
3
use std::env;
4
use std::path::Path;
5

6
#[test]
7
#[ignore]
8
#[should_panic]
9 2
fn run_makefile_not_found() {
10 2
    let global_config = GlobalConfig::new();
11

12 2
    run(
13 2
        CliArgs {
14 2
            command: "cargo make".to_string(),
15 2
            build_file: Some("bad.toml".to_string()),
16 2
            task: "empty".to_string(),
17 2
            profile: None,
18 2
            log_level: "error".to_string(),
19
            disable_color: true,
20 2
            cwd: None,
21 2
            env: None,
22 2
            env_file: None,
23
            disable_workspace: false,
24
            disable_on_error: false,
25
            allow_private: false,
26
            skip_init_end_tasks: false,
27
            disable_check_for_updates: true,
28
            print_only: false,
29
            list_all_steps: false,
30
            diff_execution_plan: false,
31
            experimental: false,
32 2
            arguments: None,
33 2
            output_format: "default".to_string(),
34 2
            output_file: None,
35
            print_time_summary: false,
36 0
        },
37
        &global_config,
38
    );
39 2
}
40

41
#[test]
42
#[ignore]
43 2
fn run_empty_task() {
44 2
    let global_config = GlobalConfig::new();
45

46 2
    run(
47 2
        CliArgs {
48 2
            command: "cargo make".to_string(),
49 2
            build_file: None,
50 2
            task: "empty".to_string(),
51 2
            profile: None,
52 2
            log_level: "error".to_string(),
53
            disable_color: true,
54 2
            cwd: None,
55 2
            env: None,
56 2
            env_file: None,
57
            disable_workspace: false,
58
            disable_on_error: false,
59
            allow_private: false,
60
            skip_init_end_tasks: false,
61
            disable_check_for_updates: true,
62
            print_only: false,
63
            list_all_steps: false,
64
            diff_execution_plan: false,
65
            experimental: false,
66 2
            arguments: None,
67 2
            output_format: "default".to_string(),
68 2
            output_file: None,
69
            print_time_summary: false,
70 0
        },
71
        &global_config,
72
    );
73 2
}
74

75
#[test]
76
#[ignore]
77 2
fn print_empty_task() {
78 2
    let global_config = GlobalConfig::new();
79

80 2
    run(
81 2
        CliArgs {
82 2
            command: "cargo make".to_string(),
83 2
            build_file: None,
84 2
            task: "empty".to_string(),
85 2
            profile: None,
86 2
            log_level: "error".to_string(),
87
            disable_color: true,
88 2
            cwd: None,
89 2
            env: None,
90 2
            env_file: None,
91
            disable_workspace: false,
92
            disable_on_error: false,
93
            allow_private: false,
94
            skip_init_end_tasks: false,
95
            disable_check_for_updates: true,
96
            print_only: true,
97
            list_all_steps: false,
98
            diff_execution_plan: false,
99
            experimental: false,
100 2
            arguments: None,
101 2
            output_format: "default".to_string(),
102 2
            output_file: None,
103
            print_time_summary: false,
104 0
        },
105
        &global_config,
106
    );
107 2
}
108

109
#[test]
110
#[ignore]
111 2
fn list_empty_task() {
112 2
    let global_config = GlobalConfig::new();
113

114 2
    run(
115 2
        CliArgs {
116 2
            command: "cargo make".to_string(),
117 2
            build_file: None,
118 2
            task: "empty".to_string(),
119 2
            profile: None,
120 2
            log_level: "error".to_string(),
121
            disable_color: true,
122 2
            cwd: None,
123 2
            env: None,
124 2
            env_file: None,
125
            disable_workspace: false,
126
            disable_on_error: false,
127
            allow_private: false,
128
            skip_init_end_tasks: false,
129
            disable_check_for_updates: true,
130
            print_only: false,
131
            list_all_steps: true,
132
            diff_execution_plan: false,
133
            experimental: false,
134 2
            arguments: None,
135 2
            output_format: "default".to_string(),
136 2
            output_file: None,
137
            print_time_summary: false,
138 0
        },
139
        &global_config,
140
    );
141 2
}
142

143
#[test]
144
#[ignore]
145 2
fn run_file_and_task() {
146 2
    let global_config = GlobalConfig::new();
147

148 2
    run(
149 2
        CliArgs {
150 2
            command: "cargo make".to_string(),
151 2
            build_file: Some("./examples/dependencies.toml".to_string()),
152 2
            task: "A".to_string(),
153 2
            profile: None,
154 2
            log_level: "error".to_string(),
155
            disable_color: true,
156 2
            cwd: None,
157 2
            env: None,
158 2
            env_file: None,
159
            disable_workspace: false,
160
            disable_on_error: false,
161
            allow_private: false,
162
            skip_init_end_tasks: false,
163
            disable_check_for_updates: true,
164
            print_only: false,
165
            list_all_steps: false,
166
            diff_execution_plan: false,
167
            experimental: false,
168 2
            arguments: None,
169 2
            output_format: "default".to_string(),
170 2
            output_file: None,
171
            print_time_summary: false,
172 0
        },
173
        &global_config,
174
    );
175 2
}
176

177
#[test]
178
#[ignore]
179 2
fn run_cwd_with_file() {
180 2
    let global_config = GlobalConfig::new();
181

182 2
    let directory = Path::new("./examples");
183 2
    assert!(env::set_current_dir(&directory).is_ok());
184

185 2
    run(
186 2
        CliArgs {
187 2
            command: "cargo make".to_string(),
188 2
            build_file: Some("./examples/dependencies.toml".to_string()),
189 2
            task: "A".to_string(),
190 2
            profile: None,
191 2
            log_level: "error".to_string(),
192
            disable_color: true,
193 2
            cwd: Some("..".to_string()),
194 2
            env: None,
195 2
            env_file: None,
196
            disable_workspace: false,
197
            disable_on_error: false,
198
            allow_private: false,
199
            skip_init_end_tasks: false,
200
            disable_check_for_updates: true,
201
            print_only: false,
202
            list_all_steps: false,
203
            diff_execution_plan: false,
204
            experimental: false,
205 2
            arguments: None,
206 2
            output_format: "default".to_string(),
207 2
            output_file: None,
208
            print_time_summary: false,
209 0
        },
210
        &global_config,
211
    );
212 2
}
213

214
#[test]
215
#[ignore]
216 2
fn run_file_not_go_to_project_root() {
217 2
    let mut global_config = GlobalConfig::new();
218 2
    global_config.search_project_root = Some(false);
219

220 2
    run(
221 2
        CliArgs {
222 2
            command: "cargo make".to_string(),
223 2
            build_file: Some("./examples/dependencies.toml".to_string()),
224 2
            task: "A".to_string(),
225 2
            profile: None,
226 2
            log_level: "error".to_string(),
227
            disable_color: true,
228 2
            cwd: None,
229 2
            env: None,
230 2
            env_file: None,
231
            disable_workspace: false,
232
            disable_on_error: false,
233
            allow_private: false,
234
            skip_init_end_tasks: false,
235
            disable_check_for_updates: true,
236
            print_only: false,
237
            list_all_steps: false,
238
            diff_execution_plan: false,
239
            experimental: false,
240 2
            arguments: None,
241 2
            output_format: "default".to_string(),
242 2
            output_file: None,
243
            print_time_summary: false,
244 0
        },
245
        &global_config,
246
    );
247 2
}
248

249
#[test]
250
#[ignore]
251 2
fn run_cwd_go_to_project_root_current_dir() {
252 2
    let mut global_config = GlobalConfig::new();
253 2
    global_config.search_project_root = Some(true);
254

255 2
    run(
256 2
        CliArgs {
257 2
            command: "cargo make".to_string(),
258 2
            build_file: Some("./examples/dependencies.toml".to_string()),
259 2
            task: "A".to_string(),
260 2
            profile: None,
261 2
            log_level: "error".to_string(),
262
            disable_color: true,
263 2
            cwd: None,
264 2
            env: None,
265 2
            env_file: None,
266
            disable_workspace: false,
267
            disable_on_error: false,
268
            allow_private: false,
269
            skip_init_end_tasks: false,
270
            disable_check_for_updates: true,
271
            print_only: false,
272
            list_all_steps: false,
273
            diff_execution_plan: false,
274
            experimental: false,
275 2
            arguments: None,
276 2
            output_format: "default".to_string(),
277 2
            output_file: None,
278
            print_time_summary: false,
279 0
        },
280
        &global_config,
281
    );
282 2
}
283

284
#[test]
285
#[ignore]
286 2
fn run_cwd_go_to_project_root_child_dir() {
287 2
    let mut global_config = GlobalConfig::new();
288 2
    global_config.search_project_root = Some(true);
289

290 2
    let directory = Path::new("./examples");
291 2
    assert!(env::set_current_dir(&directory).is_ok());
292

293 2
    run(
294 2
        CliArgs {
295 2
            command: "cargo make".to_string(),
296 2
            build_file: Some("./examples/dependencies.toml".to_string()),
297 2
            task: "A".to_string(),
298 2
            profile: None,
299 2
            log_level: "error".to_string(),
300
            disable_color: true,
301 2
            cwd: None,
302 2
            env: None,
303 2
            env_file: None,
304
            disable_workspace: false,
305
            disable_on_error: false,
306
            allow_private: false,
307
            skip_init_end_tasks: false,
308
            disable_check_for_updates: true,
309
            print_only: false,
310
            list_all_steps: false,
311
            diff_execution_plan: false,
312
            experimental: false,
313 2
            arguments: None,
314 2
            output_format: "default".to_string(),
315 2
            output_file: None,
316
            print_time_summary: false,
317 0
        },
318
        &global_config,
319
    );
320 2
}
321

322
#[test]
323
#[ignore]
324
#[should_panic]
325 2
fn run_cwd_task_not_found() {
326 2
    let global_config = GlobalConfig::new();
327

328 2
    let directory = Path::new("./examples");
329 2
    assert!(env::set_current_dir(&directory).is_ok());
330

331 2
    run(
332 2
        CliArgs {
333 2
            command: "cargo make".to_string(),
334 2
            build_file: Some("./dependencies.toml".to_string()),
335 2
            task: "A".to_string(),
336 2
            profile: None,
337 2
            log_level: "error".to_string(),
338
            disable_color: true,
339 2
            cwd: Some("..".to_string()),
340 2
            env: None,
341 2
            env_file: None,
342
            disable_workspace: false,
343
            disable_on_error: false,
344
            allow_private: false,
345
            skip_init_end_tasks: false,
346
            disable_check_for_updates: true,
347
            print_only: false,
348
            list_all_steps: false,
349
            diff_execution_plan: false,
350
            experimental: false,
351 2
            arguments: None,
352 2
            output_format: "default".to_string(),
353 2
            output_file: None,
354
            print_time_summary: false,
355 0
        },
356
        &global_config,
357
    );
358 2
}
359

360
#[test]
361
#[should_panic]
362 8
fn run_for_args_bad_subcommand() {
363 8
    let global_config = GlobalConfig::new();
364 8
    let app = create_cli(&global_config, &"make".to_string(), true);
365

366 8
    let matches = app.get_matches_from(vec!["bad"]);
367

368 8
    run_for_args(matches, &global_config, &"make".to_string(), true);
369 8
}
370

371
#[test]
372
#[ignore]
373 2
fn run_for_args_valid() {
374 2
    let global_config = GlobalConfig::new();
375 2
    let app = create_cli(&global_config, &"make".to_string(), true);
376

377 2
    let matches = app.get_matches_from(vec![
378
        "cargo",
379
        "make",
380
        "--makefile",
381
        "./examples/dependencies.toml",
382
        "-l",
383
        "error",
384
        "A",
385
        "arg1",
386
        "arg2",
387
        "arg3",
388 2
    ]);
389

390 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
391 2
}
392

393
#[test]
394
#[ignore]
395 2
fn run_for_args_with_global_config() {
396 2
    let mut global_config = GlobalConfig::new();
397 2
    global_config.log_level = Some("info".to_string());
398 2
    global_config.default_task_name = Some("empty".to_string());
399 2
    global_config.disable_color = Some(true);
400 2
    let app = create_cli(&global_config, &"make".to_string(), true);
401

402 2
    let matches = app.get_matches_from(vec!["cargo", "make"]);
403

404 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
405 2
}
406

407
#[test]
408
#[ignore]
409 2
fn run_for_args_log_level_override() {
410 2
    let global_config = GlobalConfig::new();
411 2
    let app = create_cli(&global_config, &"make".to_string(), true);
412

413 2
    let matches = app.get_matches_from(vec![
414
        "cargo",
415
        "make",
416
        "--makefile",
417
        "./examples/dependencies.toml",
418
        "-t",
419
        "A",
420
        "-l",
421
        "error",
422
        "-v",
423 2
    ]);
424

425 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
426 2
}
427

428
#[test]
429
#[ignore]
430 2
fn run_for_args_set_env_values() {
431 2
    let global_config = GlobalConfig::new();
432 2
    let app = create_cli(&global_config, &"make".to_string(), true);
433

434 2
    envmnt::set("ENV1_TEST", "EMPTY");
435 2
    envmnt::set("ENV2_TEST", "EMPTY");
436 2
    envmnt::set("ENV3_TEST", "EMPTY");
437

438 2
    let matches = app.get_matches_from(vec![
439
        "cargo",
440
        "make",
441
        "--env",
442
        "ENV1_TEST=TEST1",
443
        "--env",
444
        "ENV2_TEST=TEST2",
445
        "-e",
446
        "ENV3_TEST=TEST3",
447
        "--verbose",
448
        "--disable-check-for-updates",
449
        "-t",
450
        "empty",
451 2
    ]);
452

453 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
454

455 2
    assert_eq!(envmnt::get_or_panic("ENV1_TEST"), "TEST1");
456 2
    assert_eq!(envmnt::get_or_panic("ENV2_TEST"), "TEST2");
457 2
    assert_eq!(envmnt::get_or_panic("ENV3_TEST"), "TEST3");
458 2
}
459

460
#[test]
461
#[ignore]
462 2
fn run_for_args_set_env_via_file() {
463 2
    let global_config = GlobalConfig::new();
464 2
    let app = create_cli(&global_config, &"make".to_string(), true);
465

466 2
    envmnt::set("ENV1_TEST", "EMPTY");
467 2
    envmnt::set("ENV2_TEST", "EMPTY");
468 2
    envmnt::set("ENV3_TEST", "EMPTY");
469

470 2
    let matches = app.get_matches_from(vec![
471
        "cargo",
472
        "make",
473
        "--env-file=./examples/test.env",
474
        "--verbose",
475
        "--disable-check-for-updates",
476
        "-t",
477
        "empty",
478 2
    ]);
479

480 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
481

482 2
    assert_eq!(envmnt::get_or_panic("ENV1_TEST"), "TEST1");
483 2
    assert_eq!(envmnt::get_or_panic("ENV2_TEST"), "TEST2");
484 2
    assert_eq!(envmnt::get_or_panic("ENV3_TEST"), "VALUE OF ENV2 IS: TEST2");
485 2
}
486

487
#[test]
488
#[ignore]
489 2
fn run_for_args_set_env_both() {
490 2
    let global_config = GlobalConfig::new();
491 2
    let app = create_cli(&global_config, &"make".to_string(), true);
492

493 2
    envmnt::set("ENV1_TEST", "EMPTY");
494 2
    envmnt::set("ENV2_TEST", "EMPTY");
495 2
    envmnt::set("ENV3_TEST", "EMPTY");
496 2
    envmnt::set("ENV4_TEST", "EMPTY");
497 2
    envmnt::set("ENV5_TEST", "EMPTY");
498 2
    envmnt::set("ENV6_TEST", "EMPTY");
499

500 2
    let matches = app.get_matches_from(vec![
501
        "cargo",
502
        "make",
503
        "--env-file=./examples/test.env",
504
        "--env",
505
        "ENV4_TEST=TEST4",
506
        "--env",
507
        "ENV5_TEST=TEST5",
508
        "-e",
509
        "ENV6_TEST=TEST6",
510
        "--loglevel=error",
511
        "--disable-check-for-updates",
512
        "-t",
513
        "empty",
514 2
    ]);
515

516 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
517

518 2
    assert_eq!(envmnt::get_or_panic("ENV1_TEST"), "TEST1");
519 2
    assert_eq!(envmnt::get_or_panic("ENV2_TEST"), "TEST2");
520 2
    assert_eq!(envmnt::get_or_panic("ENV3_TEST"), "VALUE OF ENV2 IS: TEST2");
521 2
    assert_eq!(envmnt::get_or_panic("ENV4_TEST"), "TEST4");
522 2
    assert_eq!(envmnt::get_or_panic("ENV5_TEST"), "TEST5");
523 2
    assert_eq!(envmnt::get_or_panic("ENV6_TEST"), "TEST6");
524 2
}
525

526
#[test]
527
#[ignore]
528 2
fn run_for_args_print_only() {
529 2
    let global_config = GlobalConfig::new();
530 2
    let app = create_cli(&global_config, &"make".to_string(), true);
531

532 2
    let matches = app.get_matches_from(vec![
533
        "cargo",
534
        "make",
535
        "--makefile",
536
        "./examples/dependencies.toml",
537
        "-t",
538
        "A",
539
        "-l",
540
        "error",
541
        "--no-workspace",
542
        "--no-on-error",
543
        "--print-steps",
544
        "--experimental",
545 2
    ]);
546

547 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
548 2
}
549

550
#[test]
551
#[ignore]
552 2
fn run_for_args_diff_steps() {
553 2
    let global_config = GlobalConfig::new();
554 2
    let app = create_cli(&global_config, &"make".to_string(), true);
555

556 2
    let matches = app.get_matches_from(vec![
557
        "cargo",
558
        "make",
559
        "--makefile",
560
        "./examples/dependencies.toml",
561
        "-t",
562
        "empty",
563
        "-l",
564
        "error",
565
        "--no-workspace",
566
        "--diff-steps",
567 2
    ]);
568

569 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
570 2
}
571

572
#[test]
573
#[ignore]
574
#[should_panic]
575 2
fn run_protected_flow_example() {
576 2
    let global_config = GlobalConfig::new();
577 2
    let app = create_cli(&global_config, &"make".to_string(), true);
578

579 2
    let matches = app.get_matches_from(vec![
580
        "cargo",
581
        "make",
582
        "--makefile",
583
        "./examples/on_error.toml",
584 2
    ]);
585

586 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
587 2
}
588

589
#[test]
590
#[ignore]
591 2
fn run_for_args_no_task_args() {
592 2
    let global_config = GlobalConfig::new();
593 2
    let app = create_cli(&global_config, &"make".to_string(), true);
594

595 2
    envmnt::set("CARGO_MAKE_TASK_ARGS", "EMPTY");
596

597 2
    let matches = app.get_matches_from(vec![
598
        "cargo",
599
        "make",
600
        "--disable-check-for-updates",
601
        "empty",
602 2
    ]);
603

604 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
605

606 2
    assert_eq!(envmnt::get_or_panic("CARGO_MAKE_TASK_ARGS"), "");
607 2
}
608

609
#[test]
610
#[ignore]
611 2
fn run_for_args_set_task_args() {
612 2
    let global_config = GlobalConfig::new();
613 2
    let app = create_cli(&global_config, &"make".to_string(), true);
614

615 2
    envmnt::set("CARGO_MAKE_TASK_ARGS", "EMPTY");
616

617 2
    let matches = app.get_matches_from(vec![
618
        "cargo",
619
        "make",
620
        "--disable-check-for-updates",
621
        "empty",
622
        "arg1",
623
        "arg2",
624
        "arg3",
625 2
    ]);
626

627 2
    run_for_args(matches, &global_config, &"make".to_string(), true);
628

629 2
    assert_eq!(
630 2
        envmnt::get_or_panic("CARGO_MAKE_TASK_ARGS"),
631
        "arg1;arg2;arg3"
632
    );
633 2
}

Read our documentation on viewing source code .

Loading