Mercurial > hg > truffle
comparison graal/com.oracle.max.base/src/com/sun/max/test/JavaExecHarness.java @ 4142:bc8527f3071c
Adjust code base to new level of warnings.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sun, 18 Dec 2011 05:24:06 +0100 |
parents | e233f5660da4 |
children |
comparison
equal
deleted
inserted
replaced
4141:04d21be7a24f | 4142:bc8527f3071c |
---|---|
75 throw new RuntimeException(e); | 75 throw new RuntimeException(e); |
76 } catch (NoSuchFieldException e) { | 76 } catch (NoSuchFieldException e) { |
77 throw new RuntimeException(e); | 77 throw new RuntimeException(e); |
78 } | 78 } |
79 } | 79 } |
80 @Override | |
81 public int hashCode() { | |
82 return resolve().hashCode(); | |
83 } | |
80 } | 84 } |
81 | 85 |
82 public class MethodCall extends CodeLiteral { | 86 public class MethodCall extends CodeLiteral { |
83 MethodCall(String codeCall) { | 87 MethodCall(String codeCall) { |
84 super(codeCall); | 88 super(codeCall); |
152 this.expect = resultToString(run.expectedValue, run.expectedException); | 156 this.expect = resultToString(run.expectedValue, run.expectedException); |
153 this.result = result; | 157 this.result = result; |
154 } | 158 } |
155 @Override | 159 @Override |
156 public String failureMessage(TestCase testCase) { | 160 public String failureMessage(TestCase testCase) { |
157 final JavaTestCase javaTestCase = (JavaTestCase) testCase; | 161 return inputToString(run, false) + " failed with " + result + " (expected " + expect + ")"; |
158 return inputToString(javaTestCase.clazz, run, false) + " failed with " + result + " (expected " + expect + ")"; | |
159 } | 162 } |
160 | 163 |
161 } | 164 } |
162 | 165 |
163 public TestResult evaluateTest(TestEngine engine, JavaTestCase testCase) { | 166 public TestResult evaluateTest(TestEngine engine, JavaTestCase testCase) { |
187 } | 190 } |
188 | 191 |
189 public void parseTests(TestEngine engine, File file, Properties props) { | 192 public void parseTests(TestEngine engine, File file, Properties props) { |
190 try { | 193 try { |
191 // 1. find the class | 194 // 1. find the class |
192 final Class testClass = findClass(file, props); | 195 final Class testClass = findClass(file); |
193 // 2. parse the runs | 196 // 2. parse the runs |
194 final List<Run> runs = parseRuns(testClass, file, props); | 197 final List<Run> runs = parseRuns(props); |
195 if (runs != null) { | 198 if (runs != null) { |
196 // 3. add a test case to the engine | 199 // 3. add a test case to the engine |
197 engine.addTest(new JavaTestCase("exec", executor, file, testClass, runs, engine.loadingPackages())); | 200 engine.addTest(new JavaTestCase("exec", executor, file, testClass, runs, engine.loadingPackages())); |
198 } else { | 201 } else { |
199 engine.skipFile(file); | 202 engine.skipFile(file); |
201 } catch (Exception e1) { | 204 } catch (Exception e1) { |
202 throw ProgramError.unexpected(e1); | 205 throw ProgramError.unexpected(e1); |
203 } | 206 } |
204 } | 207 } |
205 | 208 |
206 private Class findClass(File file, Properties props) throws Exception { | 209 private static Class findClass(File file) throws Exception { |
207 final BufferedReader r = new BufferedReader(new FileReader(file)); | 210 final BufferedReader r = new BufferedReader(new FileReader(file)); |
208 | 211 |
209 // search for the package statement in the file. | 212 // search for the package statement in the file. |
210 String line = r.readLine(); | 213 String line = r.readLine(); |
211 for (; line != null; line = r.readLine()) { | 214 for (; line != null; line = r.readLine()) { |
240 } | 243 } |
241 r.close(); | 244 r.close(); |
242 throw ProgramError.unexpected("could not find package statement in " + file); | 245 throw ProgramError.unexpected("could not find package statement in " + file); |
243 } | 246 } |
244 | 247 |
245 private List<Run> parseRuns(Class testClass, File file, Properties props) { | 248 private List<Run> parseRuns(Properties props) { |
246 final String rstr = props.getProperty("Runs"); | 249 final String rstr = props.getProperty("Runs"); |
247 if (rstr == null) { | 250 if (rstr == null) { |
248 return null; | 251 return null; |
249 } | 252 } |
250 final List<Run> runs = new LinkedList<Run>(); | 253 final List<Run> runs = new LinkedList<>(); |
251 final CharacterIterator i = new StringCharacterIterator(rstr); | 254 final CharacterIterator i = new StringCharacterIterator(rstr); |
252 while (i.getIndex() < i.getEndIndex()) { | 255 while (i.getIndex() < i.getEndIndex()) { |
253 runs.add(parseRun(i)); | 256 runs.add(parseRun(i)); |
254 if (!skipPeekAndEat(i, ';')) { | 257 if (!skipPeekAndEat(i, ';')) { |
255 break; | 258 break; |
263 // ()=value | 266 // ()=value |
264 // (value,...)=result | 267 // (value,...)=result |
265 // value=result | 268 // value=result |
266 Object[] vals = new Object[1]; | 269 Object[] vals = new Object[1]; |
267 if (skipPeekAndEat(iterator, '(')) { | 270 if (skipPeekAndEat(iterator, '(')) { |
268 final List<Object> inputValues = new LinkedList<Object>(); | 271 final List<Object> inputValues = new LinkedList<>(); |
269 if (!skipPeekAndEat(iterator, ')')) { | 272 if (!skipPeekAndEat(iterator, ')')) { |
270 while (true) { | 273 while (true) { |
271 inputValues.add(parseValue(iterator)); | 274 inputValues.add(parseValue(iterator)); |
272 if (!skipPeekAndEat(iterator, ',')) { | 275 if (!skipPeekAndEat(iterator, ',')) { |
273 break; | 276 break; |
314 return new MethodCall(parseCodeLiteral(iterator)); | 317 return new MethodCall(parseCodeLiteral(iterator)); |
315 } | 318 } |
316 throw ProgramError.unexpected("invalid value at " + iterator.getIndex()); | 319 throw ProgramError.unexpected("invalid value at " + iterator.getIndex()); |
317 } | 320 } |
318 | 321 |
319 private ProgramError raiseParseErrorAt(String message, CharacterIterator iterator) { | 322 private static ProgramError raiseParseErrorAt(String message, CharacterIterator iterator) { |
320 final int errorIndex = iterator.getIndex(); | 323 final int errorIndex = iterator.getIndex(); |
321 final StringBuilder sb = new StringBuilder(message).append(String.format(":%n")); | 324 final StringBuilder sb = new StringBuilder(message).append(String.format(":%n")); |
322 iterator.setIndex(iterator.getBeginIndex()); | 325 iterator.setIndex(iterator.getBeginIndex()); |
323 for (char ch = iterator.current(); ch != CharacterIterator.DONE; ch = iterator.next()) { | 326 for (char ch = iterator.current(); ch != CharacterIterator.DONE; ch = iterator.next()) { |
324 sb.append(ch); | 327 sb.append(ch); |
329 } | 332 } |
330 sb.append('^'); | 333 sb.append('^'); |
331 throw ProgramError.unexpected(sb.toString()); | 334 throw ProgramError.unexpected(sb.toString()); |
332 } | 335 } |
333 | 336 |
334 private Object parseNumber(CharacterIterator iterator) { | 337 private static Object parseNumber(CharacterIterator iterator) { |
335 // an integer. | 338 // an integer. |
336 final StringBuilder buf = new StringBuilder(); | 339 final StringBuilder buf = new StringBuilder(); |
337 | 340 |
338 if (iterator.current() == '-') { | 341 if (iterator.current() == '-') { |
339 buf.append('-'); | 342 buf.append('-'); |
390 return Long.valueOf(buf.toString(), radix); | 393 return Long.valueOf(buf.toString(), radix); |
391 } | 394 } |
392 return Integer.valueOf(buf.toString(), radix); | 395 return Integer.valueOf(buf.toString(), radix); |
393 } | 396 } |
394 | 397 |
395 private void appendDigits(final StringBuilder buf, CharacterIterator iterator, int radix) { | 398 private static void appendDigits(final StringBuilder buf, CharacterIterator iterator, int radix) { |
396 while (Character.digit(iterator.current(), radix) != -1) { | 399 while (Character.digit(iterator.current(), radix) != -1) { |
397 buf.append(iterator.current()); | 400 buf.append(iterator.current()); |
398 iterator.next(); | 401 iterator.next(); |
399 } | 402 } |
400 } | 403 } |
401 | 404 |
402 private Class<? extends Throwable> parseException(CharacterIterator iterator) { | 405 private static Class<? extends Throwable> parseException(CharacterIterator iterator) { |
403 final String exceptionName = parseCodeLiteral(iterator); | 406 final String exceptionName = parseCodeLiteral(iterator); |
404 try { | 407 try { |
405 return Class.forName(exceptionName).asSubclass(Throwable.class); | 408 return Class.forName(exceptionName).asSubclass(Throwable.class); |
406 } catch (ClassNotFoundException e) { | 409 } catch (ClassNotFoundException e) { |
407 throw raiseParseErrorAt("Unknown exception type", iterator); | 410 throw raiseParseErrorAt("Unknown exception type", iterator); |
408 } | 411 } |
409 } | 412 } |
410 | 413 |
411 private String parseCodeLiteral(CharacterIterator iterator) { | 414 private static String parseCodeLiteral(CharacterIterator iterator) { |
412 final StringBuilder buf = new StringBuilder(); | 415 final StringBuilder buf = new StringBuilder(); |
413 while (true) { | 416 while (true) { |
414 final char ch = iterator.current(); | 417 final char ch = iterator.current(); |
415 if (Character.isJavaIdentifierPart(ch) || ch == '.') { | 418 if (Character.isJavaIdentifierPart(ch) || ch == '.') { |
416 buf.append(ch); | 419 buf.append(ch); |
420 } | 423 } |
421 } | 424 } |
422 return buf.toString(); | 425 return buf.toString(); |
423 } | 426 } |
424 | 427 |
425 private boolean skipPeekAndEat(CharacterIterator iterator, char c) { | 428 private static boolean skipPeekAndEat(CharacterIterator iterator, char c) { |
426 skipWhitespace(iterator); | 429 skipWhitespace(iterator); |
427 return peekAndEat(iterator, c); | 430 return peekAndEat(iterator, c); |
428 } | 431 } |
429 | 432 |
430 private boolean peekAndEat(CharacterIterator iterator, char c) { | 433 private static boolean peekAndEat(CharacterIterator iterator, char c) { |
431 if (iterator.current() == c) { | 434 if (iterator.current() == c) { |
432 iterator.next(); | 435 iterator.next(); |
433 return true; | 436 return true; |
434 } | 437 } |
435 return false; | 438 return false; |
436 } | 439 } |
437 | 440 |
438 private boolean peekAndEat(CharacterIterator iterator, String string) { | 441 private static boolean peekAndEat(CharacterIterator iterator, String string) { |
439 final int indx = iterator.getIndex(); | 442 final int indx = iterator.getIndex(); |
440 for (int j = 0; j < string.length(); j++) { | 443 for (int j = 0; j < string.length(); j++) { |
441 if (iterator.current() != string.charAt(j)) { | 444 if (iterator.current() != string.charAt(j)) { |
442 iterator.setIndex(indx); | 445 iterator.setIndex(indx); |
443 return false; | 446 return false; |
445 iterator.next(); | 448 iterator.next(); |
446 } | 449 } |
447 return true; | 450 return true; |
448 } | 451 } |
449 | 452 |
450 private void skipWhitespace(CharacterIterator iterator) { | 453 private static void skipWhitespace(CharacterIterator iterator) { |
451 while (true) { | 454 while (true) { |
452 if (!Character.isWhitespace(iterator.current())) { | 455 if (!Character.isWhitespace(iterator.current())) { |
453 break; | 456 break; |
454 } | 457 } |
455 iterator.next(); | 458 iterator.next(); |
456 } | 459 } |
457 } | 460 } |
458 | 461 |
459 private void expectChar(CharacterIterator i, char c) { | 462 private static void expectChar(CharacterIterator i, char c) { |
460 final char r = i.current(); | 463 final char r = i.current(); |
461 i.next(); | 464 i.next(); |
462 if (r != c) { | 465 if (r != c) { |
463 throw ProgramError.unexpected("parse error at " + i.getIndex() + ", expected character '" + c + "'"); | 466 throw ProgramError.unexpected("parse error at " + i.getIndex() + ", expected character '" + c + "'"); |
464 } | 467 } |
465 } | 468 } |
466 | 469 |
467 private char parseCharLiteral(CharacterIterator i) throws Exception { | 470 private static char parseEscapeChar(CharacterIterator i) { |
468 | |
469 expectChar(i, SQUOTE); | |
470 | |
471 char ch; | |
472 if (peekAndEat(i, BACKSLASH)) { | |
473 ch = parseEscapeChar(i); | |
474 } else { | |
475 ch = i.current(); | |
476 i.next(); | |
477 } | |
478 | |
479 expectChar(i, SQUOTE); | |
480 | |
481 return ch; | |
482 } | |
483 | |
484 private char parseEscapeChar(CharacterIterator i) { | |
485 final char c = i.current(); | 471 final char c = i.current(); |
486 switch (c) { | 472 switch (c) { |
487 case 'f': | 473 case 'f': |
488 i.next(); | 474 i.next(); |
489 return '\f'; | 475 return '\f'; |
522 | 508 |
523 } | 509 } |
524 return c; | 510 return c; |
525 } | 511 } |
526 | 512 |
527 private String parseStringLiteral(CharacterIterator i) { | 513 private static String parseStringLiteral(CharacterIterator i) { |
528 final StringBuilder buffer = new StringBuilder(i.getEndIndex() - i.getBeginIndex() + 1); | 514 final StringBuilder buffer = new StringBuilder(i.getEndIndex() - i.getBeginIndex() + 1); |
529 | 515 |
530 expectChar(i, QUOTE); | 516 expectChar(i, QUOTE); |
531 while (true) { | 517 while (true) { |
532 if (peekAndEat(i, QUOTE)) { | 518 if (peekAndEat(i, QUOTE)) { |
580 } | 566 } |
581 | 567 |
582 return accumul; | 568 return accumul; |
583 } | 569 } |
584 | 570 |
585 public static String inputToString(Class testClass, Run run, boolean asJavaString) { | 571 public static String inputToString(Run run, boolean asJavaString) { |
586 final StringBuilder buffer = new StringBuilder(); | 572 final StringBuilder buffer = new StringBuilder(); |
587 if (asJavaString) { | 573 if (asJavaString) { |
588 buffer.append(QUOTE); | 574 buffer.append(QUOTE); |
589 } | 575 } |
590 buffer.append("("); | 576 buffer.append("("); |