xref: /DADK/dadk/src/console/tests.rs (revision d2ade6ef037f43d0342021730a0d8b3af7bc36c1)
1 use user::UserCleanLevel;
2 
3 use super::*;
4 
5 #[test]
6 fn test_command_line_args_default() {
7     let args = CommandLineArgs::parse_from(&["dadk", "kernel"]);
8     assert_eq!(args.action, Action::Kernel);
9     assert_eq!(args.manifest_path, "dadk-manifest.toml");
10 }
11 
12 #[test]
13 fn test_command_line_args_with_manifest() {
14     // test short
15     let args = CommandLineArgs::parse_from(&["dadk", "-f", "custom-manifest.toml", "kernel"]);
16     assert_eq!(args.action, Action::Kernel);
17     assert_eq!(args.manifest_path, "custom-manifest.toml");
18     // test long
19     let args =
20         CommandLineArgs::parse_from(&["dadk", "--manifest", "custom-manifest.toml", "kernel"]);
21     assert_eq!(args.action, Action::Kernel);
22     assert_eq!(args.manifest_path, "custom-manifest.toml");
23 }
24 
25 #[test]
26 fn test_command_line_args_rootfs_subcommand() {
27     let args = CommandLineArgs::parse_from(&["dadk", "rootfs", "create"]);
28     assert!(matches!(args.action, Action::Rootfs(RootFSCommand::Create)));
29 }
30 
31 #[test]
32 fn test_command_line_args_user() {
33     let args = CommandLineArgs::parse_from(&["dadk", "user", "build"]);
34 
35     assert!(matches!(args.action, Action::User(UserCommand::Build)));
36 }
37 
38 /// 该函数测试CommandLineArgs解析器是否正确解析`dadk user clean`命令
39 #[test]
40 fn test_command_line_args_user_clean() {
41     let args = CommandLineArgs::parse_from(&["dadk", "user", "clean"]);
42     assert!(matches!(args.action, Action::User(UserCommand::Clean(_))));
43     if let Action::User(UserCommand::Clean(args)) = args.action {
44         assert_eq!(args.level, UserCleanLevel::All);
45     } else {
46         panic!("Expected UserCommand::Clean");
47     }
48 
49     // 检查 `--level` 参数
50     let args = CommandLineArgs::parse_from(&["dadk", "user", "clean", "--level", "in-src"]);
51     if let Action::User(UserCommand::Clean(args)) = args.action {
52         assert_eq!(args.level, UserCleanLevel::InSrc);
53     } else {
54         panic!("Expected UserCommand::Clean");
55     }
56 
57     // 检查 `--task` 参数
58     let args = CommandLineArgs::parse_from(&["dadk", "user", "clean", "--task", "a-0.1.0"]);
59     if let Action::User(UserCommand::Clean(args)) = args.action {
60         assert_eq!(args.task, Some("a-0.1.0".to_string()));
61     } else {
62         panic!("Expected UserCommand::Clean");
63     }
64 }
65