def check_equivalent(dep="", path="", url="", commit="", branch=""): """ Run manual and auto and compare outputs """ manual = [False, True] p = [None, None] for i in [0, 1]: init_local_crate() # run command alr_with(dep=dep, path=path, url=url, commit=commit, branch=branch, force=True, manual=manual[i]) # get output of solution p[i] = run_alr("with", "--solve").out if i == 1: assert_eq(p[0], p[1]) # Cleanup os.chdir("..") shutil.rmtree("xxx")
def create_dep(nest): """ Create the same dependency yyy under the given nest path """ os.mkdir(nest) os.chdir(nest) init_local_crate("yyy", enter=False) os.chdir("..")
def bad_action_check(type, command, name, error_re): # Test in new crate as the manifest is going to be broken init_local_crate("abc") add_action(type=type, command=command, name=name) p = run_alr("show", complain_on_error=False) assert p.status != 0, "Unexpected success" assert_match(error_re, p.out) chdir("..") rmtree("abc")
def try_path(path: str): """ Pin the parent crate using the given path, that must be equivalent to ".." """ if os.path.isdir("child"): rmtree("child") init_local_crate("child") alr_pin("parent", path=path, manual=False) # This should result in the pin being simplified to ".." assert "parent = { path='..' }\n" in lines_of(alr_manifest()), \ "Unexpected manifest contents: " + content_of(alr_manifest()) os.chdir("..") # We entered during init_local_crate()
def should_work(commit="", branch=""): os.mkdir("nest") os.chdir("nest") for crate in ["xxx", "yyy"]: init_local_crate(crate) alr_pin("zzz", url=url, commit=commit, branch=branch) os.chdir("..") os.chdir("xxx") alr_pin("yyy", path="../yyy") p = run_alr("pin") assert_match( escape("yyy file:../yyy") + ".*\n" + escape("zzz file:alire/cache/pins/zzz") + ".*" + escape(url), p.out) # Clean up for next trial os.chdir("..") os.chdir("..") git_blast("nest")
def should_not_work(commits=["", ""], branches=["", ""], match_error="FAIL"): # Commits and branches must contain two values that go into each crate pin os.mkdir("nest") os.chdir("nest") crates = ["xxx", "yyy"] for i in [0, 1]: init_local_crate(crates[i]) alr_pin("zzz", url=url, commit=commits[i], branch=branches[i]) os.chdir("..") os.chdir("xxx") alr_pin("yyy", path="../yyy", update=False) p = run_alr("pin", complain_on_error=False) assert_match(match_error, p.out) # Clean up for next trial os.chdir("..") os.chdir("..") shutil.rmtree("nest")
def check_equivalent(crate, path="", url="", commit="", branch=""): """ Run manual and auto and compare outputs """ manual = [False, True] p = [None, None] for i in [0, 1]: init_local_crate() # run command alr_pin(crate=crate, path=path, url=url, commit=commit, branch=branch, manual=manual[i]) # get pins output p[i] = run_alr("pin").out if i == 1: assert_eq(p[0], p[1]) # Cleanup os.chdir("..") shutil.rmtree("xxx")
def try_path(path: str): """ Pin the parent crate using the given path, that must be equivalent to ".." """ if os.path.isdir("child"): rmtree("child") init_local_crate("child") alr_pin("parent", path=path, manual=False) # This should result in the pin being simplified to ".." assert "parent = { path='..' }\n" in lines_of(alr_manifest()), \ "Unexpected manifest contents: " + content_of(alr_manifest()) os.chdir("..") # We entered during init_local_crate() init_local_crate("parent") # We enter it by default # Try some variants try_path("..") try_path("../") try_path("../../parent") try_path("src/../..") try_path("src/../../../parent") print('SUCCESS')
""" Test that "subdir" is rejected for source archive origins """ from drivers.alr import init_local_crate, run_alr, alr_submit from glob import glob from shutil import copyfile from subprocess import run import drivers.helpers import os # Prepare our "remote" repo init_local_crate("xxx", enter=True) # Publish it. We need to give input to alr, so we directly call it. We use the # generated location as the "online" location, and this works because we are # forcing. p = run(["alr", "-q", "-f", "-n", "publish", "--skip-build", "--tar"], input=f"file:{os.getcwd()}/alire/archives/xxx-0.0.0.tbz2\n".encode()) p.check_returncode() # Add improper subdir to manifest with open("alire/releases/xxx-0.0.0.toml", "at") as file: file.write("subdir='.'\n") # Submit manifest to index os.chdir("..") alr_submit("xxx/alire/releases/xxx-0.0.0.toml", "my_index") # Should complain on subdir field
from shutil import rmtree from subprocess import run import os def verify_manifest(): target = os.path.join("alire", "releases", "xxx-0.1.0-dev.toml") assert os.path.isfile(target), \ "Index manifest not found at expected location" # Clean up for next test rmtree(os.path.join("alire", "releases")) # Prepare our "remote" repo init_local_crate("xxx", enter=False) head_commit = init_git_repo("xxx") # Clone to a "local" repo and set minimal config assert run(["git", "clone", "xxx", "xxx_local"]).returncode == 0 os.chdir("xxx_local") assert run(["git", "config", "user.email", "*****@*****.**"]).returncode == 0 assert run(["git", "config", "user.name", "Alire Testsuite"]).returncode == 0 # Tests with different default arguments that must all succeed run_alr("--force", "publish") verify_manifest() run_alr("--force", "publish", ".") verify_manifest()
# pre/post-build expected for successful build check_not_expected('./test_post_fetch') check_expected('./test_pre_build') check_expected('./test_post_build') # updating dependencies causes the post-fetch action on the root crate to run: run_alr('update') check_expected('./test_post_fetch') check_expected('./test_pre_build') check_expected('./test_post_build') # Add a linked dependency. Since these are never "fetched", in order to # complete their action cycle, post-fetch is also run on updates init_local_crate("depended", binary=False, enter=True) # Add a similar action if on_windows(): add_action("post-fetch", ["cmd", "/C", "copy NUL test_post_fetch_dep"]) else: add_action("post-fetch", ["touch", "test_post_fetch_dep"]) check_not_expected('./test_post_fetch_dep') os.chdir("..") # Back to parent crate alr_with("depended", path="depended", update=False) run_alr("update") check_not_expected('./test_post_fetch_dep') check_expected('./depended/test_post_fetch_dep') print('SUCCESS')
""" Verify pin circularity detection """ from drivers.alr import run_alr, alr_pin, alr_unpin, alr_with, init_local_crate from drivers.asserts import assert_eq, assert_match from drivers.helpers import on_windows, dir_separator import os import re import shutil # Obvious self-pinning detection init_local_crate() alr_pin("xxx", path=".", update=False) p = run_alr("pin", complain_on_error=False) assert_match(".*" "ERROR: Pin circularity detected when adding pin xxx --> xxx:\n" "ERROR: Last manifest in the cycle is .*\n", p.out) # A real cycle detection os.chdir("..") # back to top-level shutil.rmtree("xxx") # and restart from scratch # Prepare a cycle init_local_crate("xxx", enter=False) init_local_crate("yyy", enter=False) init_local_crate("zzz") alr_pin("xxx", path="../xxx", update=False)
import os import shutil from drivers.alr import run_alr, init_local_crate, alr_pin, alr_publish, \ alr_manifest from drivers.helpers import content_of, init_git_repo from drivers.asserts import assert_eq, assert_match from subprocess import run crate = "pinner" # We create a repository with the nested crate that will act as the upstream # remote repository: start_dir = os.getcwd() init_local_crate(crate) # And add the pin directly in the remote alr_pin("unobtanium", path="/") # We can now create the upstream repo os.chdir("..") commit = init_git_repo(crate) os.rename(crate, f"{crate}.upstream") # We clone the project to obtain our local copy assert run(["git", "clone", f"{crate}.upstream", crate]).returncode == 0 # We enter the clone os.chdir(crate)
""" Test conversion of git references into commits during pinning """ from drivers.alr import run_alr, alr_with, init_local_crate from drivers.asserts import assert_eq, assert_match from drivers.helpers import init_git_repo import os import subprocess # Create a new "remote" repository with a tag that we'll use as reference init_local_crate("remote") init_git_repo(".") subprocess.run(["git", "tag", "v1"]).check_returncode() # Verify that pinning to a valid reference succeeds os.chdir("..") init_local_crate() alr_with(path="../remote", commit="v1", manual=False) p = run_alr("pin") assert_match("remote file:alire/cache/pins/remote_.{,8} ../remote#.{,8}", p.out) # Remove dependency for next test alr_with("remote", delete=True, manual=False) p = run_alr("pin") assert_eq("There are no pins\n", p.out) # Verify that pinning to an invalid reference fails p = run_alr("with",
def prepare_crate(name): """Prepare a crate with outdated lockfile""" init_local_crate(name) # Set the modification time of the lockfile behind that of the manifest info = os.stat("alire.toml") os.utime("alire.lock", (info.st_atime, info.st_mtime - 1))
""" import os import shutil from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish from drivers.helpers import init_git_repo, on_windows # from drivers.asserts import assert_eq, assert_match from subprocess import run # We create a repository with the nested crate that will act as the upstream # remote repository: start_dir = os.getcwd() os.mkdir("monoproject.upstream") os.chdir("monoproject.upstream") init_local_crate("mycrate", enter=False) os.chdir(start_dir) commit = init_git_repo("monoproject.upstream") # We clone the project to obtain our local copy assert run(["git", "clone", "monoproject.upstream", "monoproject"]).returncode == 0 # We enter the clone and verify that attempting to publish from the root fails, # as there is no crate at the git root os.chdir("monoproject") p = run_alr("publish", complain_on_error=False) assert p.status != 0, "alr failed to err as expected" assert "No Alire workspace found" in p.out, "Unexpected output: " + p.out # We enter the crate nested inside and publish.
def prepare_crate(name): """Prepare a crate with outdated lockfile""" init_local_crate(name) alr_touch_manifest()
""" import os.path from drivers.alr import run_alr, init_local_crate, alr_manifest from drivers.asserts import assert_match from drivers.helpers import content_of test_dir = os.getcwd() crate_name = "xxx" for name in [ "crate_version", "Crate_VERsion", "crate_name", "alire_", "ada_compiler_switches", "c_compiler_switches" ]: init_local_crate(name=crate_name) with open(alr_manifest(), "at") as manifest: manifest.write("[configuration.variables]\n") manifest.write('%s = {type = "Boolean", default = false}\n' % name) p = run_alr("update", complain_on_error=False) assert p.status != 0, "alr should have errored" assert_match( ".*\n" "ERROR: Configuration variable name '%s.%s' " "is reserved for Alire internal use\n.*" % (crate_name, name.lower()), p.out) os.chdir("..")
""" from drivers.alr import run_alr, alr_pin, alr_unpin, init_local_crate from drivers.asserts import assert_eq, assert_match from drivers.helpers import git_branch, git_head, init_git_repo from e3.os.fs import touch from re import escape import re import os import shutil import subprocess # "remote" is going to be the remote crate init_local_crate(name="remote", enter=False) url = os.path.join(os.getcwd(), "remote") head1 = init_git_repo("remote") os.chdir("remote") default_branch = git_branch() # Create a second branch and commit for testing subprocess.run(["git", "checkout", "-b", "devel"]).check_returncode() touch("telltale") subprocess.run(["git", "add", "telltale"]).check_returncode() subprocess.run(["git", "commit", "-m", "branching"]).check_returncode() os.chdir("..") # Now pin to the branch, and verify the telltale file exists in the checkout init_local_crate() alr_pin("remote", url=url, branch="devel")
""" Verify that, in windows, an absolute path is accepted but a relative one is preferred to be given in portable format (forward slashes) """ from drivers.alr import run_alr, alr_pin, init_local_crate from drivers.asserts import assert_eq, assert_match from drivers.helpers import on_windows import os # Dependency to be pinned with absolute path init_local_crate(name="dep_absolute") path_absolute = os.getcwd() os.chdir("..") # Dependency to be pinned with portable relative path init_local_crate(name="dep_portable", enter=False) # Dependency to be pinned with bad relative path init_local_crate(name="dep_not_portable", enter=False) # Dependent main crate init_local_crate() # Should not cause error alr_pin("dep_absolute", path=path_absolute) # Should not cause error alr_pin("dep_portable", path="../dep_portable")
from re import escape as e # Verify only external compiler available p = run_alr("toolchain") assert_match( ".*\n" # Headers "gnat_external.*Available.*Detected.*\n", p.out) # Capture version version = re.search("gnat_external ([0-9.]+)", p.out, re.MULTILINE).group(1) # Prepare a couple of dependencies, one depending on gnat, and another one # depending on gnat_native. init_local_crate("dep_generic") alr_with("gnat") os.chdir("..") init_local_crate("dep_targeted") alr_with("gnat_native") # This step also installs the native compiler os.chdir("..") # First we check that a root generic dependency mixes well with either of the # two dependencies init_local_crate("xxx_generic_generic") run_alr("with", "--use=../dep_generic") alr_with("gnat") # gnat x gnat results in the external available compiler being used, preferred
""" import os import shutil from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish from drivers.helpers import init_git_repo from subprocess import run # We create a repository with the nested crate that will act as the upstream # remote repository: start_dir = os.getcwd() index_dir = os.path.join(os.getcwd(), "my_index") os.mkdir("monoproject.upstream") os.chdir("monoproject.upstream") init_local_crate("myparent") init_local_crate("mychild") os.chdir(start_dir) commit = init_git_repo("monoproject.upstream") # We clone the project to obtain our local copy assert run(["git", "clone", "monoproject.upstream", "monoproject"]).returncode == 0 # We enter the crate nested inside and publish. os.chdir(os.path.join("monoproject", "myparent", "mychild")) run_alr("show") # Verify the crate is detected properly # This call publishes and "submits" the release to our local index alr_publish("mychild", "0.0.0", index_path=index_dir)
""" import os import shutil from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish from drivers.helpers import init_git_repo, on_windows, commit_all # from drivers.asserts import assert_eq, assert_match from subprocess import run # We create a repository with two nested crates that will act as the upstream # remote repository: start_dir = os.getcwd() os.mkdir("monoproject.upstream") os.chdir("monoproject.upstream") init_local_crate("crate1", enter=False) os.chdir(start_dir) commit1 = init_git_repo("monoproject.upstream") # We clone the project to obtain our local copy assert run(["git", "clone", "monoproject.upstream", "monoproject"]).returncode == 0 # We enter the crate nested inside and publish. # We are now at monoproject/mycrate. os.chdir("monoproject") os.chdir("crate1") alr_publish("crate1", "0.0.0", index_path=os.path.join(start_dir, "my_index")) # We create a second crate at another commit os.chdir(os.path.join(start_dir, "monoproject.upstream"))
""" Verify that recursive pins work for local paths """ from drivers.alr import run_alr, alr_pin, init_local_crate from drivers.asserts import assert_eq, assert_match import os # We are going to setup xxx --> yyy --> zzz, where xxx and zzz live at the # same level, and yyy is at ./nest/yyy init_local_crate(name="zzz", enter=False) os.mkdir("nest") os.chdir("nest") init_local_crate(name="yyy") alr_pin("zzz", path="../../zzz") os.chdir("..") os.chdir("..") init_local_crate() alr_pin("yyy", path="../nest/yyy") # Should work properly p = run_alr("pin") assert_eq('yyy file:../nest/yyy \n' 'zzz file:../zzz \n', p.out) print('SUCCESS')
""" Verify proper working of nested project files (bugfix for #634) """ import os from drivers.alr import run_alr, init_local_crate from drivers.asserts import assert_eq # Initialize a project, have it to have a nested project file init_local_crate("xxx") # Make the project file nested (sources too, to avoid modifying the gpr file) os.mkdir("nested") os.rename("xxx.gpr", os.path.join("nested", "xxx.gpr")) os.rename("src", os.path.join("nested", "src")) # Update info in the manifest with open("alire.toml", "at") as manifest: manifest.write("project-files=['nested/xxx.gpr']") # Should not fail run_alr("with", "libhello") print('SUCCESS')
import subprocess import os from drivers.alr import run_alr, init_local_crate, alr_with from drivers.asserts import assert_eq, assert_match, match_solution from re import escape as e # This test relies on three crates in the toolchain_index: # crate_conflict=1.2.3 conflicts with crate_lone* and crate_virtual* # crate_lone is a regular crate # crate_virtual has no releases, but is provided by crate_conflict_1 # Crate conflict cannot appear with any of the others in a solution, because of # its [forbids] table. init_local_crate("conflict_lone") alr_with("crate_conflict") alr_with("crate_lone") match_solution("crate_(conflict|lone)=.* \(origin:.*\)") # has origin: solved match_solution("crate_(conflict|lone)\* \(direct,missed\)") # Because of load/solving details, we do not know which of the two crates is # going to be missed/accepted in the solution, so we check there is one of each init_local_crate("conflict_virtual") alr_with("crate_conflict") alr_with("crate_virtual") match_solution("crate_(conflict|virtual)=.* \(origin:.*\)") match_solution("crate_(conflict|virtual)\* \(direct,missed\)") print('SUCCESS')
""" Check `alr build` switches to control root profile """ import os from drivers.alr import run_alr, init_local_crate, alr_with, alr_manifest from drivers.helpers import content_of from drivers.asserts import assert_match init_local_crate('lib_1', binary=False, enter=False) init_local_crate('bin_1', binary=True, enter=True) run_alr('update') def check_config(path, profile): conf = content_of(path) assert_match('.*Build_Profile : Build_Profile_Kind := "%s"' % profile, conf) lib1_config = "../lib_1/config/lib_1_config.gpr" bin_config = "config/bin_1_config.gpr" mtime = os.path.getmtime(bin_config) def check_config_changed(): global mtime last_mtime = mtime mtime = os.path.getmtime(bin_config)
Hence, we setup a root crate, that depends on "gnat" and "another_crate" (which comes first alphabetically), and verify the environment contains the compiler. """ import os import re import subprocess from drivers.alr import run_alr, init_local_crate, alr_with from drivers.asserts import assert_eq, assert_match from drivers.helpers import dir_separator # Install a binary compiler for later use run_alr("toolchain", "--select", "gnat_native") init_local_crate("another_crate") # This enters the crate alr_with("gnat") # Make it depend on gnat (in the original bug, the dependency # was also indirect, although it would have been a problem with a direct # dependency as well). os.chdir("..") # Back to root folder init_local_crate() alr_with(path="../another_crate", manual=False) # Autodetect the linked crate p = run_alr("printenv") s = re.escape(dir_separator()) # Ensure the compiler-set flag is in there: assert_match( ".*export TEST_PATH=.*"
""" Test that an empty nested table in dependencies does not cause an error. Bugfix #906: https://github.com/alire-project/alire/pull/906 """ from drivers.alr import run_alr, init_local_crate, alr_manifest from drivers.asserts import assert_match init_local_crate() # Create the problematic table with open(alr_manifest(), "at") as manifest: manifest.write("[[depends-on]]\n") manifest.write("[depends-on.'case(os)'.linux." "'case(distribution)'.ubuntu]\n") # The following command failed pre-bugfix, all is OK if it does not complain p = run_alr("update") print('SUCCESS')
# Verify removal of cached download run_alr("clean", "--cache") assert not os.path.isdir(pin_path) # Verify automatic redownload when needed run_alr("build") # Prepare for next test run_alr("with", "--del", "upstream") # Remove dependency p = run_alr("pin") assert_eq(f"There are no pins\n", p.out) # Ensure pin is gone shutil.rmtree("alire") # Total cleanup outside of alr # Initialize a git repo that will act as the "online" remote init_local_crate(name="upstream", binary=False) head = init_git_repo(".") os.chdir("..") os.rename("upstream", "upstream.git") # so it is recognized as git repo # Initialize a client crate that will use the remote init_local_crate() # This leaves us inside the new crate # Add using with directly run_alr("with", "--use", "../upstream.git", "--commit", head) verify(head) # Add using with, without head commit run_alr("with", "--use", "../upstream.git") verify()