def check(pin, error): """ Insert a pin at the end of the manifest, verify that it is rejected, and remove it from the manifest. Check the error produced against the one given """ with open(alr_manifest(), "a") as manifest: manifest.write("\n[[pins]]\n" + pin + "\n") # Remove lockfile to ensure reload if os.path.exists(alr_lockfile()): os.remove(alr_lockfile()) p = run_alr("pin", complain_on_error=False) assert p.status != 0, "Unexpected success for pin: " + pin assert_match(".*Cannot continue with invalid session.*" + error + ".*\n", p.out) # Restore the manifest lines = lines_of(alr_manifest()) lines.pop() with open(alr_manifest(), "w") as manifest: manifest.write("".join(lines)) # Verify the manifest is OK again run_alr("pin")
def verify(head=""): # Either head or branch /= "" # Check that the linked dir exists at the expected location pin_path = (f"alire/cache/pins/upstream" + ("" if head == "" else f"_{head[:8]}")) assert os.path.isdir(pin_path) # Verify info reported by alr p = run_alr("pin") assert_eq(f"upstream file:{pin_path} ../upstream.git" + ("" if head == "" else f"#{head[0:8]}") + "\n", p.out) # Verify building with pinned dependency run_alr("build") # 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
def check_run(release, match=""): p = run_alr('get', release, complain_on_error=True, quiet=True) # Enter working copy and try to run default executable os.chdir(target) p = run_alr('run', complain_on_error=not match, quiet=not match) # Check output when pattern was given: if match: assert_match(match, p.out, flags=re.S) # Otherwise run worked as expected os.chdir('..') shutil.rmtree(target)
def check_error(var_def, expected): make_manifest(var_def) p = run_alr('show', 'hello_world', complain_on_error=False, debug=False, quiet=True) assert_match('ERROR:.*' + expected + '\n', p.out)
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 match_solution(regex, escape=False, whole=False): "Check whether a regex matches the current solution" p = run_alr("with", "--solve") wrap = "" if whole else ".*" assert_match(wrap + (regex if not escape else re.escape(regex)) + wrap, p.out)
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 run(i, error): config_dir = 'alr-config-{}'.format(i) prepare_env(config_dir, os.environ) prepare_indexes(config_dir, '.', {'bad_index_{}'.format(i): { 'in_fixtures': False }}) p = run_alr("search", "--crates", complain_on_error=False, debug=False) assert_match('ERROR: {}\n'.format(error), p.out)
def invalid_key(*args): print("Running: alr config %s" % " ".join([item for item in args])) p = run_alr('config', *args, complain_on_error=False, quiet=False) assert p.status != 0, "command should fail" assert "Invalid configration key" in p.out, \ "Missing error message in: '%s" % p.out
def run(i, error): config_dir = 'alr-config-{}'.format(i) prepare_env(config_dir, os.environ) prepare_indexes( config_dir, '.', {'bad_index_{}'.format(i): {'in_fixtures': False}}) p = run_alr('list', complain_on_error=False, debug=False) assert_match( 'ERROR: {}\n' 'ERROR: alr encountered an unexpected error,' ' re-run with -d for details.\n$'.format(error), p.out)
def do_checks(path_to_dependency): flag_post_fetch = path_to_dependency + "/test_post_fetch" flag_pre_build = path_to_dependency + "/test_pre_build" flag_post_build = path_to_dependency + "/test_post_build" # Immediately after adding the dependency, this is the situation: check(flag_post_fetch, True) check(flag_pre_build, False) check(flag_post_build, False) # Remove post-fetch to check it doesn't come back unexpectedly os.remove(flag_post_fetch) # Build with error, so only pre-build runs but not post-build Path(f"{path_to_dependency}/src/empty.adb").touch() p = run_alr('build', complain_on_error=False) assert_match(".*compilation of empty.adb failed.*", p.out) # Post build shouldn't be here because of build failure check(flag_post_fetch, False) check(flag_pre_build, True) check(flag_post_build, False) os.remove(flag_pre_build) os.remove(f"{path_to_dependency}/src/empty.adb") # Build without error run_alr('build') # pre/post-build expected for successful build check(flag_post_fetch, False) check(flag_pre_build, True) check(flag_post_build, True) return # updating dependencies causes the post-fetch action to run: run_alr('update') check(flag_post_fetch, True) check(flag_pre_build, True) check(flag_post_build, True)
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 set_get_unset(key, value, image=None): if image is None: image = value # The key should not be defined get1 = run_alr('config', '--global', '--get', key, complain_on_error=False) assert get1.status != 0, 'Should not be defined' # Define it run_alr('config', '--global', '--set', key, value) # Check that it is defined check_value(key, image, local=False) # Unset it run_alr('config', '--global', '--unset', key) # Check that is it not defined anymore get3 = run_alr('config', '--global', '--get', key, complain_on_error=False) assert get3.status != 0, 'Should not be defined'
""" Test use of the available field in externals """ from glob import glob from drivers.alr import run_alr from drivers.asserts import assert_match import re import platform # 1st test: showing available information on all platforms p = run_alr('show', 'crate', '--external') assert_match( ".*Executable make --version .*" "(case Toolchain is SYSTEM => False, USER => False).*", p.out, flags=re.S) # 2nd test: showing available information on current platform p = run_alr('show', 'crate', '--external', '--system') assert_match(".*Executable make --version .* False.*", p.out, flags=re.S) # 3rd test: crate is not detected because it is unavailable. It would be # detectable otherwise (make is installed in all test images)
""" 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)
""" Test init command produced artifacts and options """ from drivers.alr import run_alr from drivers.asserts import assert_eq from drivers.helpers import compare, contents # Get crate from tarball and check contents run_alr('get', 'libhello=1.0.0-tarball') compare(contents('libhello_1.0.0_filesystem'), [ 'libhello_1.0.0_filesystem/alire', 'libhello_1.0.0_filesystem/alire.lock', 'libhello_1.0.0_filesystem/alire.toml', 'libhello_1.0.0_filesystem/libhello.gpr', 'libhello_1.0.0_filesystem/src', 'libhello_1.0.0_filesystem/src/libhello.adb', 'libhello_1.0.0_filesystem/src/libhello.ads', ]) print('SUCCESS')
""" Test unpinning """ import os from drivers.alr import run_alr from drivers.asserts import assert_eq from drivers.helpers import check_line_in # Create a new "xxx" program project run_alr('init', '--bin', 'xxx') os.chdir('xxx') # Make it depend on libhello run_alr('with', 'libhello') # Pin the version of libhello and verify pin is there run_alr('pin', 'libhello') p = run_alr('pin') assert_eq('libhello 1.0.0\n', p.out) # Unpin and verify pin is not there run_alr('pin', '--unpin', 'libhello') p = run_alr('pin') assert_eq('There are no pins\n', p.out) print('SUCCESS')
# 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() run_alr("--force", "publish", ".", "master") verify_manifest() run_alr("--force", "publish", ".", "HEAD") verify_manifest() # Verify that a dirty repo precludes publishing with open("lasagna", "wt") as file: file.write("wanted\n")
""" Test proper working of alr get --only and other follow-up commands in such an invalid solution state """ from glob import glob import os import re from drivers.alr import run_alr from drivers.asserts import assert_eq, assert_match # Get the "hello" project and enter its directory, without solving dependencies run_alr('get', 'hello', '--only') os.chdir(glob('hello*')[0]) # Verify that it has no solution p = run_alr('with', '--solve') assert_eq( 'Dependencies (direct):\n' ' libhello^1.0\n' 'Dependencies (solution):\n' ' No solving attempted\n', p.out) # Verify that it has no pins p = run_alr('pin') assert_eq('There are no pins\n', p.out) # Verify that updating it fixes the solution run_alr('update') p = run_alr('with', '--solve')
""" Test the environment set for a basic crate """ from glob import glob import os from drivers.alr import run_alr from drivers.asserts import assert_eq, assert_match import re import platform # Get the "hello" project and enter its directory run_alr('get', 'hello') os.chdir(glob('hello*')[0]) # Run it not quietly to ensure that at normal level # the output is not broken by some log message p = run_alr('printenv', quiet=False) assert_eq(0, p.status) def make_path(list): if platform.system() == 'Windows': return "\\\\".join(list) else: return "/".join(list) expected_hello_path = make_path(['.*', 'hello_1.0.1_filesystem'])
""" Verify that catalog.autoconfig works as intended (no autoadd community index) """ from glob import glob import os import re from drivers.alr import run_alr from drivers.asserts import assert_match # Since no index is configured, looking for crates will attempt to add the # community index p = run_alr("search", "hello", quiet=False) assert \ "Not configuring the community index, " + \ "disabled via index.auto_community" \ in p.out, "unexpected output: " + p.out print('SUCCESS')
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 p = run_alr("show", "xxx", complain_on_error=False) assert "forbidden extra entries: subdir" in p.out, \ "Unexpected output: " + p.out print('SUCCESS')
""" Check that a crate initialized with funny user name is loadable """ import os.path from drivers.alr import run_alr from drivers.asserts import assert_match from drivers.helpers import content_of # Preconfigure needed fields name = "Äl O'Reilly O\"Raro" run_alr("config", "--global", "--set", "user.email", "*****@*****.**") run_alr("config", "--global", "--set", "user.github_login", "abcde") run_alr("config", "--global", "--set", "user.name", name) # Create crate run_alr("init", "--bin", "xxx") # Check that it can be shown, which will load the manifest os.chdir("xxx") p = run_alr("show") assert name in p.out, f"Unexpected output: {p.out}" print('SUCCESS')
Check detection of a remote without manifest. This was allowed in the past, so legacy repositories that ignored the `alire.toml` file may run amok of this test. """ from drivers.alr import run_alr from drivers.asserts import assert_match from drivers.helpers import contents, content_of, init_git_repo, zip_dir from shutil import copyfile, rmtree from zipfile import ZipFile import os # Prepare a repo and a zipball to be used as "remote", without a manifest run_alr("init", "--bin", "xxx") # Remove the alire cache rmtree(os.path.join("xxx", "alire")) # Remove the manifest os.remove(os.path.join("xxx", "alire.toml")) # Create the zip zip_dir("xxx", "xxx.zip") # A "remote" source archive. We force to allow the test to skip the remote # check. Curl requires an absolute path to work. target = os.path.join(os.getcwd(), "xxx.zip") p = run_alr("publish", f"file:{target}", "--force", "--skip-build", complain_on_error=False) # Should fail reporting the missing manifest
def detach_origin(lines): # Return lines without "Origin:", and the origin separately # Initially the lines is simply the output, so we split: lines = lines.split('\n') newlines = [] origin = "" for line in lines: if line.startswith("Origin:"): origin = line else: newlines.append(line) return '\n'.join(newlines), origin # Outside run run1 = run_alr('show', 'libhello') run_alr('get', 'libhello') os.chdir(glob('libhello*')[0]) # Inside run run2 = run_alr('show') # The origin will change from inside the index to the deployment folder, # so we have to compare that separately out1, origin1 = detach_origin(run1.out) out2, origin2 = detach_origin(run2.out) assert_eq(out1, out2) assert origin1.endswith("libhello_1.0.0") # Original source folder
""" 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')
""" 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')
""" A test that uses an index in testsuite/fixtures """ from drivers.alr import run_alr # from drivers.asserts import assert_eq, assert_match p = run_alr('clean') print('SUCCESS')