1 package io.jawk.onetrueawk;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.nio.charset.StandardCharsets;
28 import java.nio.file.Files;
29 import java.nio.file.Path;
30 import java.util.Arrays;
31 import java.util.stream.Collectors;
32 import io.jawk.AwkTestSupport;
33 import io.jawk.CompatibilityTestResources;
34 import org.junit.AfterClass;
35 import org.junit.BeforeClass;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.junit.runners.Parameterized;
39 import org.junit.runners.Parameterized.Parameter;
40 import org.junit.runners.Parameterized.Parameters;
41
42
43
44
45
46
47
48
49 @RunWith(Parameterized.class)
50 public class BwkTIT {
51
52 private static Path bwkTDirectory;
53 private static Path scriptsDirectory;
54
55
56
57
58
59
60 @BeforeClass
61 public static void beforeAll() throws Exception {}
62
63
64
65
66
67
68
69
70 @Parameters(name = "BWK.t {0}")
71 public static Iterable<String> awkList() throws Exception {
72 bwkTDirectory = CompatibilityTestResources.resourceDirectory(BwkTIT.class, "bwk", "t");
73 if (!bwkTDirectory.toFile().isDirectory()) {
74 throw new IOException(bwkTDirectory + " is not a directory");
75 }
76 scriptsDirectory = bwkTDirectory.resolve("scripts");
77 if (!scriptsDirectory.toFile().isDirectory()) {
78 throw new IOException("scripts is not a directory");
79 }
80 File[] scriptFiles = scriptsDirectory.toFile().listFiles();
81 if (scriptFiles == null) {
82 throw new IOException("Couldn't list files in " + scriptsDirectory);
83 }
84
85 return Arrays
86 .stream(scriptFiles)
87 .filter(scriptFile -> scriptFile.getName().startsWith("t."))
88 .map(File::getName)
89 .sorted()
90 .collect(Collectors.toList());
91 }
92
93
94 @Parameter
95 public String awkName;
96
97
98
99
100
101
102 @Test
103 public void test() throws Exception {
104 Path awkPath = scriptsDirectory.resolve(awkName);
105 Path okPath = bwkTDirectory.resolve("results/" + awkName + ".ok");
106 Path inputPath = bwkTDirectory.resolve("inputs/test.data");
107
108 int expectedCode = 0;
109 if ("t.exit".equals(awkName)) {
110 expectedCode = 1;
111 } else if ("t.exit1".equals(awkName)) {
112 expectedCode = 2;
113 }
114
115 if ("t.in2".equals(awkName) || "t.intest2".equals(awkName)) {
116 String expectedResult = Files
117 .readAllLines(okPath, StandardCharsets.UTF_8)
118 .stream()
119 .sorted()
120 .collect(Collectors.joining("\n"));
121
122 AwkTestSupport
123 .awkTest("BWK.t " + awkName)
124 .script(awkPath)
125 .operand(inputPath.toString())
126 .postProcessWith(output -> Arrays.stream(output.split("\\R")).sorted().collect(Collectors.joining("\n")))
127 .expect(expectedResult)
128 .expectExit(expectedCode)
129 .build()
130 .runAndAssert();
131 } else {
132 AwkTestSupport
133 .awkTest("BWK.t " + awkName)
134 .script(awkPath)
135 .operand(inputPath.toString())
136 .expectLines(okPath)
137 .expectExit(expectedCode)
138 .build()
139 .runAndAssert();
140 }
141 }
142
143
144
145
146
147
148 @AfterClass
149 public static void afterAll() throws Exception {}
150 }