module main import os fn test_build_recipe_precedence() ! { dir := os.join_path(os.vtmp_dir(), 'vpac_recipe_choice_${os.getpid()}') os.mkdir_all(dir)! defer { os.rmdir_all(dir) or { went_on('remove the test recipes', err) } } if _ := build_recipe_name(dir) { assert false, 'an empty directory has no recipe' } for name in ['PKGBUILD', 'PKGBUILD.vsh', 'PKGBUILD.scm', 'PKGBUILD.vile'] { os.write_file(os.join_path(dir, name), '')! assert build_recipe_name(dir)! == name } } fn test_repo_name() { // the last part of the path or url, without a .git suffix. trim_right // would have cut a set of characters: digit came out as d, gist as gis cases := { 'https://example.org/mything.git': 'mything' 'https://example.org/mything': 'mything' 'https://example.org/mything.git/': 'mything' 'https://example.org/digit': 'digit' 'https://example.org/gist.git': 'gist' 'git@github.com:foo/bar.git': 'bar' 'git@host:bar.git': 'bar' '/home/u/src/thing': 'thing' '/home/u/src/thing/': 'thing' '/': '' '.': '' '': '' } for source, want in cases { got := repo_name(source) assert got == want, 'repo_name("${source}") is "${got}", not "${want}"' } } fn test_repo_work_dir_urls() ! { old := pkgbuild_dir pkgbuild_dir = '/builds' defer { pkgbuild_dir = old } name, one := repo_work_dir('u', 'https://one.example/mything.git')! _, two := repo_work_dir('u', 'https://two.example/mything.git')! _, one_slash := repo_work_dir('u', 'https://one.example/mything.git/')! assert name == 'mything' hash := one.all_after('/builds/mything-') assert one.starts_with('/builds/mything-') && hash.len == 8 assert hash.bytes().all(it.is_hex_digit()) // the same name from another source is another dir; a trailing slash is // the same source assert one != two assert one == one_slash // and a pkgbuild package of that name builds elsewhere assert one != pkgbuild_build_dir('u', 'mything')! if _, _ := repo_work_dir('u', '/') { assert false, '/ names no repo' } } fn test_is_git_url() { // the transfer urls and the .git names, as always assert is_git_url('https://example.org/mything.git') assert is_git_url('git://example.org/mything') // scp-style: user@host:path — a colon before any slash, the way git // spells a clone it will fetch over ssh assert is_git_url('git@github.com:foo/bar') assert is_git_url('git@host:bar.git') assert is_scp_remote('git@host:bar.git') // a path's slash comes first; a bare file with a colon in its name has // no slash before it either, but hosts come before the colon in scp for not in ['/home/u/mything', '/home/u/we:ird', '/dev/null:too'] { assert !is_scp_remote(not), not } } fn test_repo_work_dir_directories() ! { old := pkgbuild_dir pkgbuild_dir = '/builds' defer { pkgbuild_dir = old } tmp := os.join_path(os.vtmp_dir(), 'vpac_test_build_repo_${os.getpid()}') os.mkdir_all(os.join_path(tmp, 'a', 'mything'))! os.mkdir_all(os.join_path(tmp, 'b', 'mything'))! defer { os.rmdir_all(tmp) or {} } cwd := os.getwd() defer { os.chdir(cwd) or {} } _, a := repo_work_dir('u', os.join_path(tmp, 'a', 'mything'))! _, b := repo_work_dir('u', os.join_path(tmp, 'b', 'mything'))! assert a != b // a directory is keyed on its real path: relative, trailing slash and . // all name the same checkout os.chdir(os.join_path(tmp, 'a'))! _, rel := repo_work_dir('u', 'mything/')! os.chdir(os.join_path(tmp, 'a', 'mything'))! dot_name, dot := repo_work_dir('u', '.')! assert rel == a assert dot == a assert dot_name == 'mything' } fn test_build_refuses_noconfirm_alone() { // the build question's preset is no: --noconfirm alone would build // nothing and exit clean, so it is refused before anything is pulled build_repo(ConfigBuild{ noconfirm: true, query: ['/nonexistent/repo'] }) or { assert err.msg().contains('--nopkgbuildconfirm'), err.msg() return } assert false, 'built under --noconfirm' }