1d2ade6efSJomo use std::path::PathBuf;
2d2ade6efSJomo
3d2ade6efSJomo use dadk_config::{
4d2ade6efSJomo common::{
5d2ade6efSJomo target_arch::TargetArch,
6d2ade6efSJomo task::{
7d2ade6efSJomo BuildConfig, CleanConfig, Dependency, InstallConfig, Source, TaskEnv, TaskSource,
8d2ade6efSJomo TaskSourceType,
9d2ade6efSJomo },
10d2ade6efSJomo },
11d2ade6efSJomo user::UserConfigFile,
12d2ade6efSJomo };
13d2ade6efSJomo use test_base::{
14d2ade6efSJomo dadk_config::DadkConfigTestContext,
15d2ade6efSJomo test_context::{self as test_context, test_context},
16d2ade6efSJomo };
17d2ade6efSJomo
18d2ade6efSJomo const USER_CONFIG_LOCAL_FILE: &str = "config/userapp_config.toml";
19d2ade6efSJomo
20d2ade6efSJomo /// 测试解析DADK用户配置文件
21d2ade6efSJomo #[test_context(DadkConfigTestContext)]
22d2ade6efSJomo #[test]
test_parse_dadk_user_config(ctx: &mut DadkConfigTestContext)23d2ade6efSJomo fn test_parse_dadk_user_config(ctx: &mut DadkConfigTestContext) {
24d2ade6efSJomo let config_file = ctx.templates_dir().join(USER_CONFIG_LOCAL_FILE);
25d2ade6efSJomo assert!(config_file.exists());
26d2ade6efSJomo assert!(config_file.is_file());
27d2ade6efSJomo let r = UserConfigFile::load(&config_file);
28d2ade6efSJomo assert!(r.is_ok());
29d2ade6efSJomo let mut user_config = r.unwrap();
30d2ade6efSJomo let mut expected_user_config = UserConfigFile {
31d2ade6efSJomo name: "userapp_config".to_string(),
32d2ade6efSJomo version: "0.2.0".to_string(),
33d2ade6efSJomo description: "".to_string(),
34afbf76c1SLoGin build_once: false,
35afbf76c1SLoGin install_once: false,
36d2ade6efSJomo task_source: TaskSource {
37d2ade6efSJomo source_type: TaskSourceType::BuildFromSource,
38d2ade6efSJomo source: Source::Git,
39d2ade6efSJomo source_path: "https://git.mirrors.dragonos.org.cn/DragonOS-Community/test_git.git"
40d2ade6efSJomo .to_string(),
41d2ade6efSJomo branch: None,
42d2ade6efSJomo revision: Some("01cdc56863".to_string()),
43d2ade6efSJomo },
44d2ade6efSJomo depends: vec![
45d2ade6efSJomo Dependency {
46d2ade6efSJomo name: "depend1".to_string(),
47d2ade6efSJomo version: "0.1.1".to_string(),
48d2ade6efSJomo },
49d2ade6efSJomo Dependency {
50d2ade6efSJomo name: "depend2".to_string(),
51d2ade6efSJomo version: "0.1.2".to_string(),
52d2ade6efSJomo },
53d2ade6efSJomo ],
54*e0934047SJomo build: BuildConfig::new(
55*e0934047SJomo Some("make install".to_string()),
56*e0934047SJomo Some(PathBuf::from("config/pre_build.sh")),
57*e0934047SJomo Some(PathBuf::from("config/post_build.sh")),
58*e0934047SJomo ),
59d2ade6efSJomo install: InstallConfig::new(Some(PathBuf::from("/bin"))),
60d2ade6efSJomo clean: CleanConfig::new(Some("make clean".to_string())),
61d2ade6efSJomo envs: vec![
62d2ade6efSJomo TaskEnv::new("PATH".to_string(), "/usr/bin".to_string()),
63d2ade6efSJomo TaskEnv::new("LD_LIBRARY_PATH".to_string(), "/usr/lib".to_string()),
64d2ade6efSJomo ],
65d2ade6efSJomo target_arch: vec![TargetArch::try_from("x86_64").unwrap()],
66d2ade6efSJomo };
67d2ade6efSJomo
68d2ade6efSJomo user_config.target_arch.sort();
69d2ade6efSJomo expected_user_config.target_arch.sort();
70d2ade6efSJomo user_config.depends.sort();
71d2ade6efSJomo expected_user_config.depends.sort();
72d2ade6efSJomo user_config.envs.sort();
73d2ade6efSJomo expected_user_config.envs.sort();
74d2ade6efSJomo
75d2ade6efSJomo assert_eq!(user_config, expected_user_config)
76d2ade6efSJomo }
77