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.file.Path;
28 import java.util.Arrays;
29 import java.util.stream.Collectors;
30 import io.jawk.AwkTestSupport;
31 import io.jawk.CompatibilityTestResources;
32 import org.junit.AfterClass;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.junit.runners.Parameterized;
37 import org.junit.runners.Parameterized.Parameter;
38 import org.junit.runners.Parameterized.Parameters;
39
40
41
42
43
44
45
46
47
48 @RunWith(Parameterized.class)
49 public class BwkMiscIT {
50
51 private static Path bwkMiscDirectory;
52 private static Path scriptsDirectory;
53
54
55
56
57
58
59 @BeforeClass
60 public static void beforeAll() throws Exception {}
61
62
63
64
65
66
67
68
69 @Parameters(name = "BWK.misc {0}")
70 public static Iterable<String> awkList() throws Exception {
71 bwkMiscDirectory = CompatibilityTestResources.resourceDirectory(BwkMiscIT.class, "bwk", "misc");
72 if (!bwkMiscDirectory.toFile().isDirectory()) {
73 throw new IOException(bwkMiscDirectory + " is not a directory");
74 }
75 scriptsDirectory = bwkMiscDirectory.resolve("scripts");
76 if (!scriptsDirectory.toFile().isDirectory()) {
77 throw new IOException("scripts is not a directory");
78 }
79 File[] scriptFiles = scriptsDirectory.toFile().listFiles();
80 if (scriptFiles == null) {
81 throw new IOException("Couldn't list files in " + scriptsDirectory);
82 }
83
84 return Arrays
85 .stream(scriptFiles)
86 .filter(scriptFile -> scriptFile.getName().endsWith(".awk"))
87 .map(File::getName)
88 .sorted()
89 .collect(Collectors.toList());
90 }
91
92
93 @Parameter
94 public String awkName;
95
96
97
98
99
100
101
102 @Test
103 public void test() throws Exception {
104 Path awkFile = scriptsDirectory.resolve(awkName);
105 String shortName = awkName.substring(0, awkName.length() - 4);
106 Path inputFile = bwkMiscDirectory.resolve("inputs/" + shortName + ".in");
107 Path okFile = bwkMiscDirectory.resolve("results/" + shortName + ".ok");
108
109 AwkTestSupport
110 .cliTest("BWK.misc " + awkName)
111 .argument("-f", awkFile.toString())
112 .operand(inputFile.toString())
113 .expectLines(okFile)
114 .build()
115 .runAndAssert();
116 }
117
118
119
120
121
122
123 @AfterClass
124 public static void afterAll() throws Exception {}
125 }