File size: 1,016 Bytes
ef8334d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Check the installed command protocol and its nonzero error exits."""

import json
import subprocess
import sys

cli = sys.argv[1]


def run(text, capacity="16"):
    return subprocess.run([cli, capacity], input=text, text=True, capture_output=True)


result = run("touch 7\ntouch 3\ntouch 7\nerase 3\nplan 0 2 3 4\nplan\nrevision\n")
assert result.returncode == 0, result.stderr
batch, empty, revision = map(json.loads, result.stdout.splitlines())
assert batch == {"revision": "4", "rows": [[3, "4", True], [7, "3", False]],
                 "prefix_lengths": [2, 2, 1, 0]}
assert empty == {"revision": "4", "rows": [], "prefix_lengths": []}
assert revision == {"revision": "4"}

for text in ["touch -1", "erase 16", "touch 4294967296", "touch 1 2",
             "plan 1", "revision extra", "erase", "hello"]:
    failure = run(text)
    assert failure.returncode and "line 1" in failure.stderr, (text, failure)
assert run("plan 0", "0").returncode == 0
assert run("", "1x").returncode
print("CLI checks passed")