|
29 | 29 | import java.nio.file.Paths;
|
30 | 30 | import java.util.*;
|
31 | 31 |
|
32 |
| -import static junit.framework.TestCase.assertEquals; |
33 | 32 | import static junit.framework.TestCase.fail;
|
34 | 33 | import static junit.framework.TestCase.failNotEquals;
|
35 | 34 | import static org.junit.Assume.assumeFalse;
|
@@ -336,29 +335,6 @@ public static ErrorQueue antlrOnString(String workdir,
|
336 | 335 |
|
337 | 336 | // ---- support ----
|
338 | 337 |
|
339 |
| -// public static RuntimeTestDescriptor[] OLD_getRuntimeTestZZDescriptors(Class<?> clazz, String targetName) { |
340 |
| -// if(!TestContext.isSupportedTarget(targetName)) |
341 |
| -// return new RuntimeTestDescriptor[0]; |
342 |
| -// Class<?>[] nestedClasses = clazz.getClasses(); |
343 |
| -// List<RuntimeTestDescriptor> descriptors = new ArrayList<RuntimeTestDescriptor>(); |
344 |
| -// for (Class<?> nestedClass : nestedClasses) { |
345 |
| -// int modifiers = nestedClass.getModifiers(); |
346 |
| -// if ( RuntimeTestDescriptor.class.isAssignableFrom(nestedClass) && !Modifier.isAbstract(modifiers) ) { |
347 |
| -// try { |
348 |
| -// RuntimeTestDescriptor d = (RuntimeTestDescriptor) nestedClass.newInstance(); |
349 |
| -// if(!d.ignore(targetName)) { |
350 |
| -// d.setTarget(targetName); |
351 |
| -// descriptors.add(d); |
352 |
| -// } |
353 |
| -// } catch (Exception e) { |
354 |
| -// e.printStackTrace(System.err); |
355 |
| -// } |
356 |
| -// } |
357 |
| -// } |
358 |
| -// writeDescriptors(clazz, descriptors); |
359 |
| -// return descriptors.toArray(new RuntimeTestDescriptor[0]); |
360 |
| -// } |
361 |
| - |
362 | 338 | public static RuntimeTestDescriptor[] getRuntimeTestDescriptors(String group, String targetName) {
|
363 | 339 | final ClassLoader loader = Thread.currentThread().getContextClassLoader();
|
364 | 340 | final URL descrURL = loader.getResource("org/antlr/v4/test/runtime/descriptors/" +group);
|
@@ -397,146 +373,6 @@ public static RuntimeTestDescriptor[] getRuntimeTestDescriptors(String group, St
|
397 | 373 | return descriptors.toArray(new RuntimeTestDescriptor[0]);
|
398 | 374 | }
|
399 | 375 |
|
400 |
| - /** Write descriptor files. */ |
401 |
| - private static void writeDescriptors(Class<?> clazz, List<RuntimeTestDescriptor> descriptors) { |
402 |
| - String descrRootDir = "/Users/parrt/antlr/code/antlr4/runtime-testsuite/resources/org/antlr/v4/test/runtime/new_descriptors"; |
403 |
| - new File(descrRootDir).mkdir(); |
404 |
| - String groupName = clazz.getSimpleName(); |
405 |
| - groupName = groupName.replace("Descriptors", ""); |
406 |
| - String groupDir = descrRootDir + "/" + groupName; |
407 |
| - new File(groupDir).mkdir(); |
408 |
| - |
409 |
| - for (RuntimeTestDescriptor d : descriptors) { |
410 |
| - try { |
411 |
| - Pair<String,String> g = d.getGrammar(); |
412 |
| - String gname = g.a; |
413 |
| - String grammar = g.b; |
414 |
| - String filename = d.getTestName()+".txt"; |
415 |
| - String content = ""; |
416 |
| - String input = quoteForDescriptorFile(d.getInput()); |
417 |
| - String output = quoteForDescriptorFile(d.getOutput()); |
418 |
| - String errors = quoteForDescriptorFile(d.getErrors()); |
419 |
| - content += "[type]\n"; |
420 |
| - content += d.getTestType(); |
421 |
| - content += "\n\n"; |
422 |
| - content += "[grammar]\n"; |
423 |
| - content += grammar; |
424 |
| - if ( !content.endsWith("\n\n") ) content += "\n"; |
425 |
| - if ( d.getSlaveGrammars()!=null ) { |
426 |
| - for (Pair<String, String> slaveG : d.getSlaveGrammars()) { |
427 |
| - String sg = quoteForDescriptorFile(slaveG.b); |
428 |
| - content += "[slaveGrammar]\n"; |
429 |
| - content += sg; |
430 |
| - content += "\n"; |
431 |
| - } |
432 |
| - } |
433 |
| - if ( d.getStartRule()!=null && d.getStartRule().length()>0 ) { |
434 |
| - content += "[start]\n"; |
435 |
| - content += d.getStartRule(); |
436 |
| - content += "\n\n"; |
437 |
| - } |
438 |
| - if ( input!=null ) { |
439 |
| - content += "[input]\n"; |
440 |
| - content += input; |
441 |
| - content += "\n"; |
442 |
| - } |
443 |
| - if ( output!=null ) { |
444 |
| - content += "[output]\n"; |
445 |
| - content += output; |
446 |
| - content += "\n"; |
447 |
| - } |
448 |
| - if ( errors!=null ) { |
449 |
| - content += "[errors]\n"; |
450 |
| - content += errors; |
451 |
| - content += "\n"; |
452 |
| - } |
453 |
| - if ( d.showDFA() || d.showDiagnosticErrors() ) { |
454 |
| - content += "[flags]\n"; |
455 |
| - if (d.showDFA()) { |
456 |
| - content += "showDFA\n"; |
457 |
| - } |
458 |
| - if (d.showDiagnosticErrors()) { |
459 |
| - content += "showDiagnosticErrors\n"; |
460 |
| - } |
461 |
| - content += '\n'; |
462 |
| - } |
463 |
| - List<String> skip = new ArrayList<>(); |
464 |
| - for (String target : Targets) { |
465 |
| - if ( d.ignore(target) ) { |
466 |
| - skip.add(target); |
467 |
| - } |
468 |
| - } |
469 |
| - if ( skip.size()>0 ) { |
470 |
| - content += "[skip]\n"; |
471 |
| - for (String sk : skip) { |
472 |
| - content += sk+"\n"; |
473 |
| - } |
474 |
| - content += '\n'; |
475 |
| - } |
476 |
| - Files.write(Paths.get(groupDir + "/" + filename), content.getBytes()); |
477 |
| - } |
478 |
| - catch (IOException e) { |
479 |
| - //exception handling left as an exercise for the reader |
480 |
| - System.err.println(e.getMessage()); |
481 |
| - } |
482 |
| - } |
483 |
| - } |
484 |
| - |
485 |
| - /** Rules for strings look like this: |
486 |
| - * |
487 |
| - * [input] if one line, remove all WS before/after |
488 |
| - * a b |
489 |
| - * |
490 |
| - * [input] need whitespace |
491 |
| - * """34 |
492 |
| - * 34""" |
493 |
| - * |
494 |
| - * [input] single quote char, remove all WS before/after |
495 |
| - * " |
496 |
| - * |
497 |
| - * [input] same as "b = 6\n" in java |
498 |
| - * """b = 6 |
499 |
| - * """ |
500 |
| - * |
501 |
| - * [input] |
502 |
| - * """a """ space and no newline inside |
503 |
| - * |
504 |
| - * [input] same as java string "\"aaa" |
505 |
| - * "aaa |
506 |
| - * |
507 |
| - * [input] ignore front/back \n except leave last \n |
508 |
| - * a |
509 |
| - * b |
510 |
| - * c |
511 |
| - * d |
512 |
| - */ |
513 |
| - private static String quoteForDescriptorFile(String s) { |
514 |
| - if ( s==null ) { |
515 |
| - return null; |
516 |
| - } |
517 |
| - long nnl = s.chars().filter(ch -> ch == '\n').count(); |
518 |
| - |
519 |
| - if ( s.endsWith(" ") || // whitespace matters |
520 |
| - (nnl==1&&s.endsWith("\n")) || // "b = 6\n" |
521 |
| - s.startsWith("\n") ) { // whitespace matters |
522 |
| - return "\"\"\"" + s + "\"\"\"\n"; |
523 |
| - } |
524 |
| - if ( s.endsWith(" \n") || s.endsWith("\n\n") ) { |
525 |
| - return "\"\"\"" + s + "\"\"\"\n"; |
526 |
| - } |
527 |
| - if ( nnl==0 ) { // one line input |
528 |
| - return s + "\n"; |
529 |
| - } |
530 |
| - if ( nnl>1 && s.endsWith("\n") ) { |
531 |
| - return s; |
532 |
| - } |
533 |
| - if ( !s.endsWith("\n") ) { // "a\n b" |
534 |
| - return "\"\"\"" + s + "\"\"\"\n"; |
535 |
| - } |
536 |
| - |
537 |
| - return s; |
538 |
| - } |
539 |
| - |
540 | 376 | /** Read stuff like:
|
541 | 377 | [grammar]
|
542 | 378 | grammar T;
|
@@ -773,4 +609,174 @@ protected static void assertCorrectOutput(RuntimeTestDescriptor descriptor, Runt
|
773 | 609 | ">.");
|
774 | 610 | }
|
775 | 611 | }
|
| 612 | + |
| 613 | + // ---------------------------------------------------------------------------- |
| 614 | + // stuff used during conversion that I don't want to throw away yet and we might lose if |
| 615 | + // I squash this branch unless I keep it around in a comment or something |
| 616 | + // ---------------------------------------------------------------------------- |
| 617 | + |
| 618 | +// public static RuntimeTestDescriptor[] OLD_getRuntimeTestDescriptors(Class<?> clazz, String targetName) { |
| 619 | +// if(!TestContext.isSupportedTarget(targetName)) |
| 620 | +// return new RuntimeTestDescriptor[0]; |
| 621 | +// Class<?>[] nestedClasses = clazz.getClasses(); |
| 622 | +// List<RuntimeTestDescriptor> descriptors = new ArrayList<RuntimeTestDescriptor>(); |
| 623 | +// for (Class<?> nestedClass : nestedClasses) { |
| 624 | +// int modifiers = nestedClass.getModifiers(); |
| 625 | +// if ( RuntimeTestDescriptor.class.isAssignableFrom(nestedClass) && !Modifier.isAbstract(modifiers) ) { |
| 626 | +// try { |
| 627 | +// RuntimeTestDescriptor d = (RuntimeTestDescriptor) nestedClass.newInstance(); |
| 628 | +// if(!d.ignore(targetName)) { |
| 629 | +// d.setTarget(targetName); |
| 630 | +// descriptors.add(d); |
| 631 | +// } |
| 632 | +// } catch (Exception e) { |
| 633 | +// e.printStackTrace(System.err); |
| 634 | +// } |
| 635 | +// } |
| 636 | +// } |
| 637 | +// writeDescriptors(clazz, descriptors); |
| 638 | +// return descriptors.toArray(new RuntimeTestDescriptor[0]); |
| 639 | +// } |
| 640 | + |
| 641 | + |
| 642 | + /** Write descriptor files. */ |
| 643 | +// private static void writeDescriptors(Class<?> clazz, List<RuntimeTestDescriptor> descriptors) { |
| 644 | +// String descrRootDir = "/Users/parrt/antlr/code/antlr4/runtime-testsuite/resources/org/antlr/v4/test/runtime/new_descriptors"; |
| 645 | +// new File(descrRootDir).mkdir(); |
| 646 | +// String groupName = clazz.getSimpleName(); |
| 647 | +// groupName = groupName.replace("Descriptors", ""); |
| 648 | +// String groupDir = descrRootDir + "/" + groupName; |
| 649 | +// new File(groupDir).mkdir(); |
| 650 | +// |
| 651 | +// for (RuntimeTestDescriptor d : descriptors) { |
| 652 | +// try { |
| 653 | +// Pair<String,String> g = d.getGrammar(); |
| 654 | +// String gname = g.a; |
| 655 | +// String grammar = g.b; |
| 656 | +// String filename = d.getTestName()+".txt"; |
| 657 | +// String content = ""; |
| 658 | +// String input = quoteForDescriptorFile(d.getInput()); |
| 659 | +// String output = quoteForDescriptorFile(d.getOutput()); |
| 660 | +// String errors = quoteForDescriptorFile(d.getErrors()); |
| 661 | +// content += "[type]\n"; |
| 662 | +// content += d.getTestType(); |
| 663 | +// content += "\n\n"; |
| 664 | +// content += "[grammar]\n"; |
| 665 | +// content += grammar; |
| 666 | +// if ( !content.endsWith("\n\n") ) content += "\n"; |
| 667 | +// if ( d.getSlaveGrammars()!=null ) { |
| 668 | +// for (Pair<String, String> slaveG : d.getSlaveGrammars()) { |
| 669 | +// String sg = quoteForDescriptorFile(slaveG.b); |
| 670 | +// content += "[slaveGrammar]\n"; |
| 671 | +// content += sg; |
| 672 | +// content += "\n"; |
| 673 | +// } |
| 674 | +// } |
| 675 | +// if ( d.getStartRule()!=null && d.getStartRule().length()>0 ) { |
| 676 | +// content += "[start]\n"; |
| 677 | +// content += d.getStartRule(); |
| 678 | +// content += "\n\n"; |
| 679 | +// } |
| 680 | +// if ( input!=null ) { |
| 681 | +// content += "[input]\n"; |
| 682 | +// content += input; |
| 683 | +// content += "\n"; |
| 684 | +// } |
| 685 | +// if ( output!=null ) { |
| 686 | +// content += "[output]\n"; |
| 687 | +// content += output; |
| 688 | +// content += "\n"; |
| 689 | +// } |
| 690 | +// if ( errors!=null ) { |
| 691 | +// content += "[errors]\n"; |
| 692 | +// content += errors; |
| 693 | +// content += "\n"; |
| 694 | +// } |
| 695 | +// if ( d.showDFA() || d.showDiagnosticErrors() ) { |
| 696 | +// content += "[flags]\n"; |
| 697 | +// if (d.showDFA()) { |
| 698 | +// content += "showDFA\n"; |
| 699 | +// } |
| 700 | +// if (d.showDiagnosticErrors()) { |
| 701 | +// content += "showDiagnosticErrors\n"; |
| 702 | +// } |
| 703 | +// content += '\n'; |
| 704 | +// } |
| 705 | +// List<String> skip = new ArrayList<>(); |
| 706 | +// for (String target : Targets) { |
| 707 | +// if ( d.ignore(target) ) { |
| 708 | +// skip.add(target); |
| 709 | +// } |
| 710 | +// } |
| 711 | +// if ( skip.size()>0 ) { |
| 712 | +// content += "[skip]\n"; |
| 713 | +// for (String sk : skip) { |
| 714 | +// content += sk+"\n"; |
| 715 | +// } |
| 716 | +// content += '\n'; |
| 717 | +// } |
| 718 | +// Files.write(Paths.get(groupDir + "/" + filename), content.getBytes()); |
| 719 | +// } |
| 720 | +// catch (IOException e) { |
| 721 | +// //exception handling left as an exercise for the reader |
| 722 | +// System.err.println(e.getMessage()); |
| 723 | +// } |
| 724 | +// } |
| 725 | +// } |
| 726 | +// |
| 727 | +// /** Rules for strings look like this: |
| 728 | +// * |
| 729 | +// * [input] if one line, remove all WS before/after |
| 730 | +// * a b |
| 731 | +// * |
| 732 | +// * [input] need whitespace |
| 733 | +// * """34 |
| 734 | +// * 34""" |
| 735 | +// * |
| 736 | +// * [input] single quote char, remove all WS before/after |
| 737 | +// * " |
| 738 | +// * |
| 739 | +// * [input] same as "b = 6\n" in java |
| 740 | +// * """b = 6 |
| 741 | +// * """ |
| 742 | +// * |
| 743 | +// * [input] |
| 744 | +// * """a """ space and no newline inside |
| 745 | +// * |
| 746 | +// * [input] same as java string "\"aaa" |
| 747 | +// * "aaa |
| 748 | +// * |
| 749 | +// * [input] ignore front/back \n except leave last \n |
| 750 | +// * a |
| 751 | +// * b |
| 752 | +// * c |
| 753 | +// * d |
| 754 | +// */ |
| 755 | +// private static String quoteForDescriptorFile(String s) { |
| 756 | +// if ( s==null ) { |
| 757 | +// return null; |
| 758 | +// } |
| 759 | +// long nnl = s.chars().filter(ch -> ch == '\n').count(); |
| 760 | +// |
| 761 | +// if ( s.endsWith(" ") || // whitespace matters |
| 762 | +// (nnl==1&&s.endsWith("\n")) || // "b = 6\n" |
| 763 | +// s.startsWith("\n") ) { // whitespace matters |
| 764 | +// return "\"\"\"" + s + "\"\"\"\n"; |
| 765 | +// } |
| 766 | +// if ( s.endsWith(" \n") || s.endsWith("\n\n") ) { |
| 767 | +// return "\"\"\"" + s + "\"\"\"\n"; |
| 768 | +// } |
| 769 | +// if ( nnl==0 ) { // one line input |
| 770 | +// return s + "\n"; |
| 771 | +// } |
| 772 | +// if ( nnl>1 && s.endsWith("\n") ) { |
| 773 | +// return s; |
| 774 | +// } |
| 775 | +// if ( !s.endsWith("\n") ) { // "a\n b" |
| 776 | +// return "\"\"\"" + s + "\"\"\"\n"; |
| 777 | +// } |
| 778 | +// |
| 779 | +// return s; |
| 780 | +// } |
| 781 | + |
776 | 782 | }
|
0 commit comments