-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest1.py
More file actions
38 lines (35 loc) · 890 Bytes
/
test1.py
File metadata and controls
38 lines (35 loc) · 890 Bytes
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
30
31
32
33
34
35
36
37
38
import sys
import subprocess
def run(cmd, inp=''):
p = subprocess.Popen(cmd, shell=False, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(inp.encode('utf-8'))
p.stdin.close()
out = p.stdout.read()
rc = p.wait()
return (rc, out)
TEST = r'''
abcd => abcd
ab"c"d => abcd
ab""c""d => abcd
ab\cd => ab\cd
ab\\cd => ab\\cd
"abcd" => abcd
"ab\cd" => ab\cd
"ab\"cd" => ab"cd
"ab\\cd" => ab\cd
"ab""cd" => abcd
"ab" "cd" => ab cd
'''
TEST = TEST.split("\n")
TEST = [tuple(line.split("=>", 2)) for line in TEST if line]
TEST = [(a.strip(), b.strip()) for (a, b) in TEST]
for (a, b) in TEST:
out = run(["./csvecho", a])
if out[0] != 0:
print(f"{a} ... failed\n")
sys.exit(1)
res = out[1].rstrip()
if res != b.encode('utf-8'):
print(f"{a} ... {res} != {b}")
sys.exit(1)
print(f"{a} => {b} (ok)")