forked from OpenCobolIDE/OpenCobolIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_compiler.py
166 lines (146 loc) · 5.2 KB
/
test_compiler.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
"""
Tests the compiler module
"""
import os
import re
import pytest
from open_cobol_ide import system
from open_cobol_ide.compilers import (
GnuCobolCompiler, get_file_type)
from open_cobol_ide.enums import FileType, GnuCobolStandard
from open_cobol_ide.settings import Settings
def test_extensions():
exts = GnuCobolCompiler().extensions
if system.windows:
assert exts[0] == '.exe'
assert exts[1] == '.dll'
else:
assert exts[0] == ''
assert exts[1] == '.so'
def test_is_working():
assert GnuCobolCompiler().is_working()
def test_get_version():
prog = re.compile(r'^.*\d.\d.\d$')
assert prog.match(GnuCobolCompiler().get_version(include_all=False)) \
is not None
@pytest.mark.parametrize('path, ftype', [
('test/testfiles/TEST-PRINTER.cbl', FileType.EXECUTABLE),
('test/testfiles/VIRTUAL-PRINTER.cbl', FileType.MODULE),
('test/testfiles/VIRTUAL-PRINTER2.cbl', FileType.MODULE),
])
def test_get_file_type(path, ftype):
assert get_file_type(path) == ftype
@pytest.mark.parametrize('file_type, expected', [
(FileType.EXECUTABLE, '.exe' if system.windows else ''),
(FileType.MODULE, '.dll' if system.windows else '.so'),
])
def test_type_extension(file_type, expected):
assert GnuCobolCompiler().extension_for_type(file_type) == expected
exe_ext = GnuCobolCompiler().extension_for_type(FileType.EXECUTABLE)
dll_ext = GnuCobolCompiler().extension_for_type(FileType.MODULE)
@pytest.mark.parametrize('free, std, ftype, expected_opts', [
(False, GnuCobolStandard.default, FileType.EXECUTABLE, [
'-x',
'-o', '%s' % os.path.join('bin', 'HelloWorld' + exe_ext),
'-std=default',
'-Wall',
'-debug'
]),
(True, GnuCobolStandard.default, FileType.EXECUTABLE, [
'-x',
'-o', '%s' % os.path.join('bin', 'HelloWorld' + exe_ext),
'-std=default',
'-Wall',
'-debug',
'-free'
]),
(False, GnuCobolStandard.default, FileType.MODULE, [
'-o', '%s' % os.path.join('bin', 'HelloWorld' + dll_ext),
'-std=default',
'-Wall',
'-debug'
]),
(True, GnuCobolStandard.default, FileType.MODULE, [
'-o', '%s' % os.path.join('bin', 'HelloWorld' + dll_ext),
'-std=default',
'-Wall',
'-debug',
'-free'
]),
(False, GnuCobolStandard.mf, FileType.EXECUTABLE, [
'-x',
'-o', '%s' % os.path.join('bin', 'HelloWorld' + exe_ext),
'-std=mf',
'-Wall',
'-debug'
]),
(True, GnuCobolStandard.mf, FileType.EXECUTABLE, [
'-x',
'-o', '%s' % os.path.join('bin', 'HelloWorld' + exe_ext),
'-std=mf',
'-Wall',
'-debug',
'-free'
]),
(False, GnuCobolStandard.mf, FileType.MODULE, [
'-o', '%s' % os.path.join('bin', 'HelloWorld' + dll_ext),
'-std=mf',
'-Wall',
'-debug'
]),
(True, GnuCobolStandard.mf, FileType.MODULE, [
'-o', '%s' % os.path.join('bin', 'HelloWorld' + dll_ext),
'-std=mf',
'-Wall',
'-debug',
'-free'
])
])
def test_make_command_exe(free, std, ftype, expected_opts):
compiler = GnuCobolCompiler()
settings = Settings()
settings.free_format = free
settings.cobol_standard = std
pgm, options = compiler.make_command(['HelloWorld.cbl'], ftype, 'bin')
assert pgm == Settings().compiler_path
for o, eo in zip(options, expected_opts):
assert o == eo
settings.free_format = free
settings.cobol_standard = GnuCobolStandard.default
settings.free_format = False
@pytest.mark.parametrize('path, ftype, expected_results, output_file_path', [
('test/testfiles/HelloWorld.cbl', FileType.EXECUTABLE, (0, []),
'test/testfiles/bin/HelloWorld' + exe_ext),
('test/testfiles/MALFORMED.cbl', FileType.EXECUTABLE,
(1,
[('syntax error, unexpected CONFIGURATION, expecting "end of file"', 2,
10, 0, None, None, 'MALFORMED.cbl')]), ''),
])
def test_compile(path, ftype, expected_results, output_file_path):
results = GnuCobolCompiler().compile(path, ftype)
assert results[0] == expected_results[0]
assert len(results[1]) >= len(expected_results[1])
if output_file_path:
assert os.path.exists(output_file_path)
os.remove(output_file_path)
@pytest.mark.parametrize('filename, expected_results', [
# test 1
('test/testfiles/HelloWorld.cbl', []),
# test 2
('test/testfiles/TEST-PRINTER.cbl',
[os.path.normpath('test/testfiles/VIRTUAL-PRINTER.cbl')]),
('test/testfiles/TEST-PRINTER3.cbl',
[os.path.normpath('test/testfiles/VIRTUAL-PRINTER.cbl')]),
# test 3
('test/testfiles/TEST-PRINTER2.cbl',
[os.path.normpath('test/testfiles/VIRTUAL-PRINTER.cbl'),
os.path.normpath('test/testfiles/VIRTUAL-PRINTER2.cbl')])
])
def test_get_dependencies(filename, expected_results):
results = GnuCobolCompiler().get_dependencies(filename)
assert sorted(results) == sorted(expected_results)
def test_parse_output():
code = "HelloWorld.cbl: 5: Error: Invalid indicator ';' at column 7 \n" \
"HelloWorld.cbl: 3: Error: TCOP: No such file or directory"
msgs = GnuCobolCompiler.parse_output(code, 'test/testfiles')
assert len(msgs) == 2