| 1 |
""" |
| 2 |
Tests for proper publishing using a local repo as reference |
| 3 |
""" |
| 4 |
|
| 5 |
from drivers.alr import init_local_crate, run_alr |
| 6 |
from drivers.asserts import assert_match |
| 7 |
from drivers.helpers import init_git_repo |
| 8 |
from glob import glob |
| 9 |
from shutil import rmtree |
| 10 |
from subprocess import run |
| 11 |
|
| 12 |
import os |
| 13 |
|
| 14 |
|
| 15 |
def verify_manifest(): |
| 16 |
target = os.path.join("alire", "releases", "xxx-0.1.0-dev.toml") |
| 17 |
assert os.path.isfile(target), \ |
| 18 |
"Index manifest not found at expected location" |
| 19 |
# Clean up for next test |
| 20 |
rmtree(os.path.join("alire", "releases")) |
| 21 |
|
| 22 |
|
| 23 |
# Prepare our "remote" repo |
| 24 |
init_local_crate("xxx", enter=False) |
| 25 |
head_commit = init_git_repo("xxx") |
| 26 |
|
| 27 |
# Clone to a "local" repo and set minimal config |
| 28 |
assert run(["git", "clone", "xxx", "xxx_local"]).returncode == 0 |
| 29 |
os.chdir("xxx_local") |
| 30 |
assert run(["git", "config", "user.email", "[email protected]"]).returncode == 0 |
| 31 |
assert run(["git", "config", "user.name", "Alire Testsuite"]).returncode == 0 |
| 32 |
|
| 33 |
# Tests with different default arguments that must all succeed |
| 34 |
run_alr("--force", "publish") |
| 35 |
verify_manifest() |
| 36 |
|
| 37 |
run_alr("--force", "publish", ".") |
| 38 |
verify_manifest() |
| 39 |
|
| 40 |
run_alr("--force", "publish", ".", "master") |
| 41 |
verify_manifest() |
| 42 |
|
| 43 |
run_alr("--force", "publish", ".", "HEAD") |
| 44 |
verify_manifest() |
| 45 |
|
| 46 |
# Verify that a dirty repo precludes publishing |
| 47 |
with open("lasagna", "wt") as file: |
| 48 |
file.write("wanted\n") |
| 49 |
|
| 50 |
assert run(["git", "add", "lasagna"]).returncode == 0 |
| 51 |
|
| 52 |
p = run_alr("--force", "publish", complain_on_error=False) |
| 53 |
assert_match(".*You have unstaged changes.*", p.out) |
| 54 |
|
| 55 |
# Even if changes are committed but not pushed |
| 56 |
assert run(["git", "add", "."]).returncode == 0 |
| 57 |
assert run(["git", "commit", "-a", "-m", "please"]).returncode == 0 |
| 58 |
p = run_alr("--force", "publish", complain_on_error=False) |
| 59 |
assert_match(".*Your branch is ahead of remote.*", p.out) |
| 60 |
|
| 61 |
print('SUCCESS') |