]> git.proxmox.com Git - mirror_xterm.js.git/blob - test/escape_sequence_files/run_tests.py
selecting sucessful tests
[mirror_xterm.js.git] / test / escape_sequence_files / run_tests.py
1 from glob import glob
2 import os
3 import sys
4 import termios
5 import atexit
6
7 BASE_DIR = os.path.dirname(os.path.abspath(__file__))
8
9
10 def enable_echo(fd, enabled):
11 (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) = termios.tcgetattr(fd)
12 if enabled:
13 lflag |= termios.ECHO
14 else:
15 lflag &= ~termios.ECHO
16 new_attr = [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]
17 termios.tcsetattr(fd, termios.TCSANOW, new_attr)
18
19 atexit.register(enable_echo, sys.stdin.fileno(), True)
20
21 output = []
22
23
24 def log(append=False, *s):
25 if append:
26 output[-1] += ' ' + ' '.join(str(part) for part in s)
27 else:
28 output.append(' '.join(str(part) for part in s))
29
30
31 def reset_terminal():
32 sys.stdout.write('\x1bc\x1b[H')
33 sys.stdout.flush()
34
35
36 def test():
37 count = 0
38 passed = 0
39 for i, testfile in enumerate(sorted(glob(os.path.join(BASE_DIR, '*.in')))):
40 count += 1
41 log(False, os.path.basename(testfile))
42 reset_terminal()
43 with open(testfile) as test:
44 sys.stdout.write('\x1b]0;%s\x07' % os.path.basename(testfile))
45 sys.stdout.write(test.read()+'\x1bt')
46 sys.stdout.flush()
47 with open(os.path.join(os.path.dirname(testfile),
48 os.path.basename(testfile).split('.')[0]+'.text')) as expected:
49 terminal_output = sys.stdin.read()
50 if not terminal_output:
51 # we are in xterm
52 continue
53 if terminal_output != expected.read():
54 log(True, '\x1b[31merror\x1b[0m')
55 with open(os.path.join(os.path.dirname(testfile), 'output',
56 os.path.basename(testfile)), 'w') as t_out:
57 t_out.write(terminal_output)
58 else:
59 passed += 1
60 log(True, '\x1b[32mpass\x1b[0m')
61 return count, passed
62
63
64 if __name__ == '__main__':
65 enable_echo(sys.stdin.fileno(), False)
66 count, passed = test()
67 enable_echo(sys.stdin.fileno(), True)
68 reset_terminal()
69 for i in range(len(output)/2+1):
70 if not (i+1) % 25:
71 sys.stdin.read()
72 print ''.join(i.ljust(40) for i in output[i*2:i*2+2])
73 print '\x1b[33mcoverage: %s/%s (%d%%) tests passed.\x1b[0m' % (passed, count, passed*100/count)