(String[] args)
| 191 | private static boolean ok = true; |
| 192 | |
| 193 | @SuppressWarnings("deprecation") // intentional use of ParserInput.fromLatin1() |
| 194 | public static void main(String[] args) throws Exception { |
| 195 | File root = new File("third_party/bazel"); // blaze |
| 196 | if (!root.exists()) { |
| 197 | root = new File("."); // bazel |
| 198 | } |
| 199 | File testdata = new File(root, "src/test/java/net/starlark/java/eval/testdata"); |
| 200 | for (String name : testdata.list()) { |
| 201 | File file = new File(testdata, name); |
| 202 | String content = Files.asCharSource(file, UTF_8).read(); |
| 203 | int linenum = 1; |
| 204 | for (String chunk : Splitter.on("\n---\n").split(content)) { |
| 205 | // prepare chunk |
| 206 | StringBuilder buf = new StringBuilder(); |
| 207 | for (int i = 1; i < linenum; i++) { |
| 208 | buf.append('\n'); |
| 209 | } |
| 210 | buf.append(chunk); |
| 211 | if (false) { |
| 212 | System.err.printf("%s:%d: <<%s>>\n", file, linenum, buf); |
| 213 | } |
| 214 | |
| 215 | // extract expectations: ### "regular expression" |
| 216 | Map<Pattern, Integer> expectations = new HashMap<>(); |
| 217 | for (int i = chunk.indexOf("###"); i >= 0; i = chunk.indexOf("###", i)) { |
| 218 | int j = chunk.indexOf("\n", i); |
| 219 | if (j < 0) { |
| 220 | j = chunk.length(); |
| 221 | } |
| 222 | |
| 223 | int line = linenum + newlines(chunk.substring(0, i)); |
| 224 | String comment = chunk.substring(i + 3, j); |
| 225 | i = j; |
| 226 | |
| 227 | // Compile regular expression in comment. |
| 228 | Pattern pattern; |
| 229 | try { |
| 230 | pattern = Pattern.compile(comment.trim()); |
| 231 | } catch (PatternSyntaxException ex) { |
| 232 | System.err.printf("%s:%d: invalid regexp: %s\n", file, line, ex.getMessage()); |
| 233 | ok = false; |
| 234 | continue; |
| 235 | } |
| 236 | |
| 237 | if (false) { |
| 238 | System.err.printf("%s:%d: expectation '%s'\n", file, line, pattern); |
| 239 | } |
| 240 | expectations.put(pattern, line); |
| 241 | } |
| 242 | |
| 243 | // parse & execute |
| 244 | boolean utf8ByteStrings = |
| 245 | Boolean.getBoolean("net.starlark.java.eval.ScriptTest.utf8ByteStrings"); |
| 246 | ParserInput input; |
| 247 | if (utf8ByteStrings) { |
| 248 | |
| 249 | input = ParserInput.fromLatin1(buf.toString().getBytes(UTF_8), file.toString()); |
| 250 | } else { |
nothing calls this directly
no test coverage detected