|
1 |
| -// #[cfg(test)] |
2 |
| -// mod tests { |
3 |
| -// use libmake::cli::build; |
4 |
| - |
5 |
| -// #[test] |
6 |
| -// // Test that the arguments for the build CLI are correctly set |
7 |
| -// fn test_build_cli_args() { |
8 |
| -// // Define the expected argument values |
9 |
| -// let arg_specs = [ |
10 |
| -// ("author", "Me"), |
11 |
| -// ("build", "build.rs"), |
12 |
| -// ("categories", "['category 1', 'category 2']"), |
13 |
| -// ("description", "A library for doing things"), |
14 |
| -// ("documentation", "https://lib.rs/crates/my_library"), |
15 |
| -// ("edition", "2021"), |
16 |
| -// ("email", "[email protected]"), |
17 |
| -// ("homepage", "https://test.com"), |
18 |
| -// ("keywords", "['keyword1', 'keyword2']"), |
19 |
| -// ("license", "MIT OR Apache-2.0"), |
20 |
| -// ("name", "my_library"), |
21 |
| -// ("output", "my_library"), |
22 |
| -// ("readme", "README.md"), |
23 |
| -// ("repository", "https://github.com/example/my_library"), |
24 |
| -// ("rustversion", "1.75.0"), |
25 |
| -// ("version", "0.2.2"), |
26 |
| -// ("website", "https://test.com"), |
27 |
| -// ]; |
28 |
| - |
29 |
| -// // Call the build_cli function to get the command-line arguments |
30 |
| -// let args = build().unwrap(); |
31 |
| - |
32 |
| -// // Iterate through the expected argument values |
33 |
| -// for (arg_name, expected_value) in &arg_specs { |
34 |
| -// // Get the actual value for the argument |
35 |
| -// let arg_value: Option<&String> = args.get_one(arg_name); |
36 |
| - |
37 |
| -// // Compare the actual and expected values |
38 |
| -// assert_eq!( |
39 |
| -// Some(&(*expected_value).to_string()), |
40 |
| -// arg_value, |
41 |
| -// "Incorrect value for argument {arg_name}", |
42 |
| -// ); |
43 |
| -// } |
44 |
| -// } |
45 |
| -// } |
| 1 | +#[cfg(test)] |
| 2 | +mod tests { |
| 3 | + use libmake::cli::{build, create_arg}; |
| 4 | + |
| 5 | + #[test] |
| 6 | + fn test_build_manual_subcommand() { |
| 7 | + let matches = build(); |
| 8 | + assert!(matches.is_ok()); |
| 9 | + } |
| 10 | + |
| 11 | + #[test] |
| 12 | + fn test_create_arg() { |
| 13 | + // Test case 1: Create an argument with all fields |
| 14 | + let arg_info = ( |
| 15 | + "name", |
| 16 | + Some("default"), |
| 17 | + "help message", |
| 18 | + 'n', |
| 19 | + "name", |
| 20 | + "NAME", |
| 21 | + ); |
| 22 | + let arg = create_arg(arg_info); |
| 23 | + assert_eq!(arg.get_id(), "name"); |
| 24 | + assert_eq!(arg.get_help().unwrap().to_string(), "help message"); |
| 25 | + assert_eq!(arg.get_short().unwrap(), 'n'); |
| 26 | + assert_eq!(arg.get_long().unwrap(), "name"); |
| 27 | + |
| 28 | + // Test case 2: Create an argument without a default value |
| 29 | + let arg_info = |
| 30 | + ("name", None, "help message", 'n', "name", "NAME"); |
| 31 | + let arg = create_arg(arg_info); |
| 32 | + assert_eq!(arg.get_id(), "name"); |
| 33 | + assert_eq!(arg.get_help().unwrap().to_string(), "help message"); |
| 34 | + assert_eq!(arg.get_short().unwrap(), 'n'); |
| 35 | + assert_eq!(arg.get_long().unwrap(), "name"); |
| 36 | + |
| 37 | + // Test case 3: Create an argument with only required fields |
| 38 | + let arg_info = ("name", None, "", 'n', "name", "NAME"); |
| 39 | + let arg = create_arg(arg_info); |
| 40 | + assert_eq!(arg.get_id(), "name"); |
| 41 | + assert_eq!(arg.get_short().unwrap(), 'n'); |
| 42 | + assert_eq!(arg.get_long().unwrap(), "name"); |
| 43 | + |
| 44 | + // Test case 4: Create an argument with a multi-word long flag |
| 45 | + let arg_info = |
| 46 | + ("name", None, "help message", 'n', "long-flag", "NAME"); |
| 47 | + let arg = create_arg(arg_info); |
| 48 | + assert_eq!(arg.get_long().unwrap(), "long-flag"); |
| 49 | + |
| 50 | + // Test case 5: Argument with an empty help message |
| 51 | + let arg_info = ( |
| 52 | + "name", None, "", // Empty help message |
| 53 | + 'n', "name", "NAME", |
| 54 | + ); |
| 55 | + let arg = create_arg(arg_info); |
| 56 | + |
| 57 | + // Updated assertion |
| 58 | + assert!(arg.get_help().is_some()); // Help should be set, even if empty |
| 59 | + |
| 60 | + // Optionally, depending on the implementation of StyledStr: |
| 61 | + assert_eq!(arg.get_help().unwrap().to_string(), ""); // Check if the help string is indeed empty |
| 62 | + |
| 63 | + // Test case 6: Long argument name |
| 64 | + let arg_info = ( |
| 65 | + "very-long-argument-name", |
| 66 | + None, |
| 67 | + "help", |
| 68 | + 'v', |
| 69 | + "very-long-argument-name", |
| 70 | + "NAME", |
| 71 | + ); |
| 72 | + let arg = create_arg(arg_info); |
| 73 | + assert_eq!(arg.get_id(), "very-long-argument-name"); |
| 74 | + } |
| 75 | + |
| 76 | +} |
0 commit comments