diff --git a/local/recipes/system/cub/source/cub-lib/src/cookbook.rs b/local/recipes/system/cub/source/cub-lib/src/cookbook.rs index 6c1cd35de8..83ae4f50d4 100644 --- a/local/recipes/system/cub/source/cub-lib/src/cookbook.rs +++ b/local/recipes/system/cub/source/cub-lib/src/cookbook.rs @@ -505,6 +505,44 @@ mod tests { let recipe = generate_recipe(&pkg).expect("multi-source should emit recipe"); assert!(recipe.contains("[source.patches]")); assert!(recipe.contains("tar = \"https://example.com/extra.tar.gz\"")); + // Round-trip: the generated TOML must be re-parseable. + let value: toml::Value = + toml::from_str(&recipe).expect("multi-source recipe must be valid TOML"); + let patches = value + .get("source") + .and_then(|s| s.get("patches")) + .expect("[source.patches] must exist"); + assert_eq!( + patches.get("tar").and_then(|v| v.as_str()), + Some("https://example.com/extra.tar.gz") + ); + } + + #[test] + fn multi_source_git_aux_is_well_formed() { + let mut pkg = base_pkg(BuildTemplate::Cargo); + pkg.source.sources[0].name = None; + pkg.source.sources.push(SourceEntry { + name: Some("vendor-fork".to_string()), + source_type: SourceType::Git, + url: "https://github.com/redbear-os/vendor-fork.git".to_string(), + sha256: String::new(), + rev: "main".to_string(), + branch: String::new(), + }); + + let recipe = generate_recipe(&pkg).expect("multi-source git aux should emit"); + let value: toml::Value = toml::from_str(&recipe).expect("recipe must be valid TOML"); + let aux = value + .get("source") + .and_then(|s| s.get("vendor-fork")) + .expect("[source.vendor-fork] must exist"); + assert_eq!( + aux.get("git").and_then(|v| v.as_str()), + Some("https://github.com/redbear-os/vendor-fork.git") + ); + assert_eq!(aux.get("rev").and_then(|v| v.as_str()), Some("main")); + assert_eq!(aux.get("shallow_clone").and_then(|v| v.as_bool()), Some(true)); } #[test] diff --git a/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs b/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs index 52dfccfd4a..0a534b7c1e 100644 --- a/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs +++ b/local/recipes/system/cub/source/cub-lib/src/pkgbuild.rs @@ -1086,6 +1086,42 @@ prepare() { assert!(result.rbpkg.build.install_script.is_empty()); } + #[test] + fn prepare_with_control_structures_extracts_all_lines() { + let input = r#" +pkgname=demo +pkgver=1.0.0 +pkgrel=1 +source=('https://example.com/demo.tar.xz') +sha256sums=('abc') + +prepare() { + if [ -f Makefile.am ]; then + autoreconf -fi + else + ./bootstrap.sh + fi + for patch in ../*.patch; do + patch -p1 < "$patch" + done +} +"#; + let result = convert_pkgbuild(input).expect("convert prepare() with control flow"); + assert_eq!( + result.rbpkg.build.prepare, + vec![ + "if [ -f Makefile.am ]; then".to_string(), + "autoreconf -fi".to_string(), + "else".to_string(), + "./bootstrap.sh".to_string(), + "fi".to_string(), + "for patch in ../*.patch; do".to_string(), + "patch -p1 < \"$patch\"".to_string(), + "done".to_string(), + ] + ); + } + #[test] fn warning_mentions_prepare_alongside_build_and_package() { let input = r#"