|
| 1 | +""" |
| 2 | +Verify that no extraneous output is printed during `alr printenv` even when |
| 3 | +sync/update needed. |
| 4 | +""" |
| 5 | + |
| 6 | +import os |
| 7 | +import shutil |
| 8 | +from drivers.alr import alr_lockfile, alr_with, init_local_crate, run_alr, run_alr_interactive |
| 9 | +from drivers.asserts import assert_eq |
| 10 | + |
| 11 | + |
| 12 | +def check_output(output : str): |
| 13 | + # Split in lines and verify that every line is an export |
| 14 | + for line in output.splitlines(): |
| 15 | + assert line.startswith("export ") |
| 16 | + |
| 17 | + |
| 18 | +# We create a new crate with some dependencies and delete the `alire` forder. |
| 19 | +# This forces a sync that normally would print stuff that is unwanted during |
| 20 | +# `alr printenv`. |
| 21 | + |
| 22 | +init_local_crate() |
| 23 | +alr_with("hello") |
| 24 | + |
| 25 | +shutil.rmtree("alire") |
| 26 | + |
| 27 | +# This one will perform a silent sync |
| 28 | +p1 = run_alr("printenv", "--unix", quiet=False) # This one would fail <2.1 |
| 29 | + |
| 30 | +# Verify the sync happened |
| 31 | +assert os.path.isfile(alr_lockfile()) |
| 32 | + |
| 33 | +# A second, quiet printenv should always work properly |
| 34 | +p2 = run_alr("printenv", "--unix", quiet=True) |
| 35 | + |
| 36 | +# Output should match |
| 37 | +assert_eq(p1.out, p2.out) |
| 38 | + |
| 39 | +# Also check that every line is an export and not something else. |
| 40 | +# We do not check the specific contents as they vary between OSes and build modes. |
| 41 | +check_output(p1.out) |
| 42 | + |
| 43 | +# Test that a non-interactive run also completes without trying to interact or |
| 44 | +# with unexpected output |
| 45 | + |
| 46 | +p3 = run_alr_interactive(["printenv", "--unix"], [], []) |
| 47 | +assert_eq(p2.out, p3) |
| 48 | + |
| 49 | + |
| 50 | +print("SUCCESS") |
0 commit comments