Debian Codegraph @

testsuite/tests/pin/manifest-invalid-pins/test.py

raw
1 """
2 Verify various bad pins in the manifest are rejected
3 """
4
5 from drivers.alr import run_alr, init_local_crate, alr_lockfile, alr_manifest
6 from drivers.helpers import lines_of
7 from drivers.asserts import assert_match
8
9 import os.path
10
11
12 def check(pin, error):
13 """
14 Insert a pin at the end of the manifest, verify that it is rejected, and
15 remove it from the manifest. Check the error produced against the one given
16 """
17 with open(alr_manifest(), "a") as manifest:
18 manifest.write("\n[[pins]]\n" + pin + "\n")
19
20 # Remove lockfile to ensure reload
21 if os.path.exists(alr_lockfile()):
22 os.remove(alr_lockfile())
23
24 p = run_alr("pin", complain_on_error=False)
25 assert p.status != 0, "Unexpected success for pin: " + pin
26 assert_match(".*Cannot continue with invalid session.*" +
27 error + ".*\n",
28 p.out)
29
30 # Restore the manifest
31 lines = lines_of(alr_manifest())
32 lines.pop()
33 with open(alr_manifest(), "w") as manifest:
34 manifest.write("".join(lines))
35
36 # Verify the manifest is OK again
37 run_alr("pin")
38
39
40 init_local_crate()
41
42 # Invalid empty pins
43 check("foo = { }", "invalid pin description")
44 check("foo = ''", "Malformed semantic version in pin")
45
46 # Single string must be a version
47 check("foo = 'https://github.com/alire-project/alire.git'",
48 "Malformed semantic version in pin")
49
50 # Mixed incompatible fields
51 check("foo = { version = '3', url='https://' }",
52 "forbidden extra entries")
53 check("foo = { path = '/', url='https://' }",
54 "forbidden extra entries")
55 check("foo = { path = '/', version='6976' }",
56 "forbidden extra entries")
57 check("foo = { path = '/', "
58 "commit = '0123456789012345678901234567890123456789' }",
59 "forbidden extra entries")
60
61 # Extraneous field
62 check("foo = { wont_ever_exist='' }", "invalid pin description")
63
64 # Commit without url
65 check("foo = { commit = '0123456789012345678901234567890123456789' }",
66 "invalid pin description")
67
68 # Invalid commit
69 check("foo = { url = 'https://', commit = '1234abcd' }",
70 "invalid commit")
71
72 # Extra unknown field
73 check("foo = { version = '3', wont_exist='' }",
74 "forbidden extra entries")
75 check("foo = { path = '/', wont_exist='' }",
76 "forbidden extra entries")
77 check("foo = { url = 'https://', wont_exist='' }",
78 "forbidden extra entries")
79 check("foo = { url = 'https://', wont_exist='', "
80 "commit = '0123456789012345678901234567890123456789' }",
81 "forbidden extra entries")
82
83 print('SUCCESS')