1 use clap::CommandFactory; 2 use clap::Parser; 3 4 use crate::utils::get_help; 5 use crate::utils::get_long_help; 6 7 #[test] app_name_in_short_help_from_struct()8fn app_name_in_short_help_from_struct() { 9 #[derive(Parser)] 10 #[command(name = "my-cmd")] 11 struct MyApp {} 12 13 let help = get_help::<MyApp>(); 14 15 assert!(help.contains("my-cmd")); 16 } 17 18 #[test] app_name_in_long_help_from_struct()19fn app_name_in_long_help_from_struct() { 20 #[derive(Parser)] 21 #[command(name = "my-cmd")] 22 struct MyApp {} 23 24 let help = get_help::<MyApp>(); 25 26 assert!(help.contains("my-cmd")); 27 } 28 29 #[test] app_name_in_short_help_from_enum()30fn app_name_in_short_help_from_enum() { 31 #[derive(Parser)] 32 #[command(name = "my-cmd")] 33 enum MyApp {} 34 35 let help = get_help::<MyApp>(); 36 37 assert!(help.contains("my-cmd")); 38 } 39 40 #[test] app_name_in_long_help_from_enum()41fn app_name_in_long_help_from_enum() { 42 #[derive(Parser)] 43 #[command(name = "my-cmd")] 44 enum MyApp {} 45 46 let help = get_long_help::<MyApp>(); 47 48 assert!(help.contains("my-cmd")); 49 } 50 51 #[test] app_name_in_short_version_from_struct()52fn app_name_in_short_version_from_struct() { 53 #[derive(Parser)] 54 #[command(name = "my-cmd")] 55 struct MyApp {} 56 57 let version = MyApp::command().render_version(); 58 59 assert!(version.contains("my-cmd")); 60 } 61 62 #[test] app_name_in_long_version_from_struct()63fn app_name_in_long_version_from_struct() { 64 #[derive(Parser)] 65 #[command(name = "my-cmd")] 66 struct MyApp {} 67 68 let version = MyApp::command().render_long_version(); 69 70 assert!(version.contains("my-cmd")); 71 } 72 73 #[test] app_name_in_short_version_from_enum()74fn app_name_in_short_version_from_enum() { 75 #[derive(Parser)] 76 #[command(name = "my-cmd")] 77 enum MyApp {} 78 79 let version = MyApp::command().render_version(); 80 81 assert!(version.contains("my-cmd")); 82 } 83 84 #[test] app_name_in_long_version_from_enum()85fn app_name_in_long_version_from_enum() { 86 #[derive(Parser)] 87 #[command(name = "my-cmd")] 88 enum MyApp {} 89 90 let version = MyApp::command().render_long_version(); 91 92 assert!(version.contains("my-cmd")); 93 } 94