Debian Codegraph @

testsuite/tests/monorepo/doubly-nested/test.py

raw
1 """
2 Publish a doubly-nested crate: ./gitrepo/parent/child and test using it
3 """
4
5 import os
6 import shutil
7
8 from drivers.alr import run_alr, init_local_crate, alr_with, alr_publish
9 from drivers.helpers import init_git_repo
10 from subprocess import run
11
12 # We create a repository with the nested crate that will act as the upstream
13 # remote repository:
14 start_dir = os.getcwd()
15 index_dir = os.path.join(os.getcwd(), "my_index")
16 os.mkdir("monoproject.upstream")
17 os.chdir("monoproject.upstream")
18 init_local_crate("myparent")
19 init_local_crate("mychild")
20 os.chdir(start_dir)
21 commit = init_git_repo("monoproject.upstream")
22
23 # We clone the project to obtain our local copy
24 assert run(["git", "clone",
25 "monoproject.upstream", "monoproject"]).returncode == 0
26
27 # We enter the crate nested inside and publish.
28 os.chdir(os.path.join("monoproject", "myparent", "mychild"))
29 run_alr("show") # Verify the crate is detected properly
30
31 # This call publishes and "submits" the release to our local index
32 alr_publish("mychild", "0.1.0-dev", index_path=index_dir)
33
34 # Publish also its parent for later test
35 os.chdir("..")
36 alr_publish("myparent", "0.1.0-dev", index_path=index_dir)
37
38 # Verify that the crate can be got and compiled, and expected location
39 os.chdir(start_dir)
40 run_alr("get", "--build", "mychild")
41 assert os.path.isdir(os.path.join(f"monoproject_{commit[:8]}",
42 "myparent", "mychild")), \
43 "Expected directory does not exist"
44
45 # Verify that the crate is usable as a dependency, and expected location
46 init_local_crate("top")
47 alr_with("mychild")
48 run_alr("build")
49 assert os.path.isdir(os.path.join("alire", "cache", "dependencies",
50 f"monoproject_{commit[:8]}",
51 "myparent", "mychild")), \
52 "Expected directory does not exist"
53
54 # Verify that "with"ing the parent does not result in a new checkout
55 alr_with("myparent", update=False)
56 p = run_alr("-v", "update", quiet=False)
57 assert "Skipping checkout of already available myparent=0.1.0-dev" in p.out, \
58 "Expected output not found: " + p.out
59
60 # Verify the build is successful. As the dependencies were created with --bin,
61 # they will be built even if not "with"ed in the Ada code to make their binary
62 # available to the root crate during the build process.
63 run_alr("build")
64
65 print('SUCCESS')