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