Skip to content

Commit 873637c

Browse files
committed
Added "gradlew verify"
1 parent d6e63d4 commit 873637c

4 files changed

Lines changed: 50 additions & 46 deletions

File tree

build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,8 @@ configure(subprojects - project(':onjava')) {
184184
compile project(':onjava')
185185
}
186186
}
187+
188+
task verify(type:Exec) {
189+
println("execute 'gradlew run' first")
190+
commandLine 'python', 'test_output.py'
191+
}

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
org.gradle.daemon=true
2+
org.gradle.parallel=true

phase1.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

test_output.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,53 @@
55
# (2) If direct comparison of actual output with output stored in Java file fails:
66
# (3) Use chain of responsibility to successively try filters until one matches or all fail
77
from pathlib import Path
8+
import textwrap
89
import re
910

11+
def fill_to_width(text):
12+
result = ""
13+
for line in text.splitlines():
14+
result += textwrap.fill(line, width=59) + "\n"
15+
return result.strip()
16+
17+
def adjust_lines(text):
18+
text = text.replace("\0", "NUL")
19+
lines = text.splitlines()
20+
slug = lines[0]
21+
if "(First and Last " in slug:
22+
num_of_lines = int(slug.split()[5])
23+
adjusted = lines[:num_of_lines + 1] +\
24+
["...________...________...________...________..."] +\
25+
lines[-num_of_lines:]
26+
return "\n".join(adjusted)
27+
elif "(First " in slug:
28+
num_of_lines = int(slug.split()[3])
29+
adjusted = lines[:num_of_lines + 1] +\
30+
[" ..."]
31+
return "\n".join(adjusted)
32+
else:
33+
return text
34+
35+
def phase1():
36+
"""
37+
(0) Do first/last lines before formatting to width
38+
(1) Combine output and error (if present) files
39+
(2) Format all output to width limit
40+
(3) Add closing '*/'
41+
"""
42+
for outfile in Path(".").rglob("*.out"):
43+
out_text = adjust_lines(outfile.read_text())
44+
phase_1 = outfile.with_suffix(".p1")
45+
with phase_1.open('w') as phs1:
46+
phs1.write(fill_to_width(out_text) + "\n")
47+
errfile = outfile.with_suffix(".err")
48+
if errfile.exists():
49+
phs1.write("___[ Error Output ]___\n")
50+
phs1.write(fill_to_width(errfile.read_text()) + "\n")
51+
phs1.write("*/\n")
1052

1153
if __name__ == '__main__':
54+
phase1()
1255
find_output = re.compile(r"/\* (Output:.*)\*/", re.DOTALL) # should space be \s+ ??
1356
for outfile in Path(".").rglob("*.p1"):
1457
javafile = outfile.with_suffix(".java")

0 commit comments

Comments
 (0)