// Unit tests for package.build_script_cmd — asserts exact command strings. import core.package import core.str mut g_fail = 0 proc expect(label: string, got: string, want: string) if str.equals(got, want) println("PASS: " + label) else g_fail = g_fail + 1 println("FAIL: " + label) println(" got: " + got) println(" want: " + want) end if end expect proc main() println("=== build_script_cmd tests ===") // Normal install: root "/", no chroot -> CORAL_ROOT="/" prefix let normal = package.new_script_ctx("/", false) expect("normal .sh", package.build_script_cmd(normal, "/tmp/x/.SCRIPTS/post-install.sh", "post-install.sh", "\"1.0\"", true), "CORAL_ROOT=\"/\" zsh \"/tmp/x/.SCRIPTS/post-install.sh\" \"1.0\"") // Host-fallback: root "/mnt", do_chroot false -> CORAL_ROOT="/mnt" prefix, host path let host = package.new_script_ctx("/mnt", false) expect("host-fallback .sh", package.build_script_cmd(host, "/tmp/x/.SCRIPTS/post-install.sh", "post-install.sh", "\"1.0\"", true), "CORAL_ROOT=\"/mnt\" zsh \"/tmp/x/.SCRIPTS/post-install.sh\" \"1.0\"") // Bare executable (is_sh false): no zsh wrapper expect("normal bare", package.build_script_cmd(normal, "/tmp/x/.SCRIPTS/post-install", "post-install", "\"1.0\"", false), "CORAL_ROOT=\"/\" \"/tmp/x/.SCRIPTS/post-install\" \"1.0\"") // Empty args: no trailing space expect("normal no-args", package.build_script_cmd(normal, "/tmp/x/.SCRIPTS/pre-remove.sh", "pre-remove.sh", "", true), "CORAL_ROOT=\"/\" zsh \"/tmp/x/.SCRIPTS/pre-remove.sh\"") // Confined: root "/mnt", do_chroot true -> chroot prefix, in-root /.SCRIPTS path, CORAL_ROOT="/" let jail = package.new_script_ctx("/mnt", true) expect("chroot .sh", package.build_script_cmd(jail, "/tmp/x/.SCRIPTS/post-install.sh", "post-install.sh", "\"1.0\"", true), "chroot \"/mnt\" env CORAL_ROOT=\"/\" zsh \"/.SCRIPTS/post-install.sh\" \"1.0\"") expect("chroot bare", package.build_script_cmd(jail, "/tmp/x/.SCRIPTS/post-install", "post-install", "\"1.0\"", false), "chroot \"/mnt\" env CORAL_ROOT=\"/\" \"/.SCRIPTS/post-install\" \"1.0\"") println("") if g_fail == 0 println("RESULT: ALL PASS") else println("RESULT: FAIL (" + str.from_int(g_fail) + " failures)") end if end main