Runs all tests. @param suites root element @throws IOException query exception
(final FBuilder suites)
| 68 | * @throws IOException query exception |
| 69 | */ |
| 70 | public void test(final FBuilder suites) throws IOException { |
| 71 | final FBuilder suite = FElem.build(Q_TESTSUITE).attr(Q_NAME, file.url()); |
| 72 | final ArrayList<StaticFunc> beforeModule = new ArrayList<>(0); |
| 73 | final ArrayList<StaticFunc> afterModule = new ArrayList<>(0); |
| 74 | final ArrayList<StaticFunc> before = new ArrayList<>(0); |
| 75 | final ArrayList<StaticFunc> after = new ArrayList<>(0); |
| 76 | final ArrayList<QNm> beforeFilter = new ArrayList<>(); |
| 77 | final ArrayList<QNm> afterFilter = new ArrayList<>(); |
| 78 | final ArrayList<StaticFunc> test = new ArrayList<>(0); |
| 79 | final Performance perf = new Performance(); |
| 80 | |
| 81 | try(QueryContext qc = new QueryContext(ctx)) { |
| 82 | input = file.readString(); |
| 83 | qc.parse(input, file.path()); |
| 84 | |
| 85 | // loop through all functions |
| 86 | for(final StaticFunc sf : qc.functions) { |
| 87 | // find Unit annotations |
| 88 | final AnnList anns = sf.anns; |
| 89 | boolean unit = false; |
| 90 | for(final Ann ann : anns) { |
| 91 | final Annotation ad = ann.definition; |
| 92 | unit = unit || ad != null && eq(ad.name.uri(), QueryText.UNIT_URI); |
| 93 | } |
| 94 | if(!unit) continue; |
| 95 | |
| 96 | // Unit function: |
| 97 | if(anns.contains(PRIVATE)) throw UNIT_PRIVATE_X.get(null, sf.name.local()); |
| 98 | if(sf.arity() > 0) throw UNIT_NOARGS_X.get(null, sf.name.local()); |
| 99 | |
| 100 | if(anns.contains(_UNIT_BEFORE_MODULE)) beforeModule.add(sf); |
| 101 | if(anns.contains(_UNIT_AFTER_MODULE)) afterModule.add(sf); |
| 102 | final Ann b = anns.get(_UNIT_BEFORE); |
| 103 | if(b != null) { |
| 104 | before.add(sf); |
| 105 | beforeFilter.add(name(sf, b)); |
| 106 | } |
| 107 | final Ann a = anns.get(_UNIT_AFTER); |
| 108 | if(a != null) { |
| 109 | after.add(sf); |
| 110 | afterFilter.add(name(sf, a)); |
| 111 | } |
| 112 | if(anns.contains(_UNIT_TEST)) test.add(sf); |
| 113 | } |
| 114 | |
| 115 | // call initializing functions before first test |
| 116 | for(final StaticFunc sf : beforeModule) eval(sf); |
| 117 | |
| 118 | for(final StaticFunc sf : test) { |
| 119 | // check arguments |
| 120 | final AnnList anns = sf.anns; |
| 121 | final Ann ann = anns.get(_UNIT_TEST); |
| 122 | final Value value = ann.value(); |
| 123 | final long vs = value.size(); |
| 124 | |
| 125 | // expected error code |
| 126 | QNm code = null; |
| 127 | if(vs == 2 && eq(Q_EXPECTED.string(), value.itemAt(0).string(null))) { |