| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.testdriver; |
| 9 |
|
| 10 |
|
| 11 |
import net.sf.saxon.Configuration; |
| 12 |
import net.sf.saxon.Version; |
| 13 |
import net.sf.saxon.dom.DOMObjectModel; |
| 14 |
import net.sf.saxon.lib.Feature; |
| 15 |
import net.sf.saxon.lib.FeatureKeys; |
| 16 |
import net.sf.saxon.om.TreeModel; |
| 17 |
import net.sf.saxon.s9api.*; |
| 18 |
import net.sf.saxon.s9api.streams.Steps; |
| 19 |
import org.w3c.dom.Document; |
| 20 |
|
| 21 |
import javax.xml.stream.XMLStreamException; |
| 22 |
import java.io.File; |
| 23 |
import java.io.IOException; |
| 24 |
import java.util.*; |
| 25 |
import java.util.function.Predicate; |
| 26 |
import java.util.regex.Pattern; |
| 27 |
|
| 28 |
import static net.sf.saxon.s9api.streams.Predicates.attributeEq; |
| 29 |
import static net.sf.saxon.s9api.streams.Predicates.hasAttribute; |
| 30 |
import static net.sf.saxon.s9api.streams.Steps.*; |
| 31 |
import static net.sf.saxon.s9api.streams.XdmCollectors.asString; |
| 32 |
|
| 33 |
public abstract class TestDriver { |
| 34 |
|
| 35 |
protected String catalogFileName; |
| 36 |
private XdmNode catalogNode; |
| 37 |
protected String exceptionsFileName = "exceptions.xml"; |
| 38 |
protected String resultsDir = null; |
| 39 |
protected TestReport resultsDoc; |
| 40 |
protected int successes = 0; |
| 41 |
protected int failures = 0; |
| 42 |
protected int notrun = 0; |
| 43 |
protected int wrongErrorResults = 0; |
| 44 |
protected TestDriverShell shell = new TestDriverShell(); |
| 45 |
protected boolean unfolded = false; |
| 46 |
protected boolean saveResults = false; |
| 47 |
protected boolean runPostureAndSweepTests = true; |
| 48 |
protected int generateByteCode = 1; |
| 49 |
protected boolean debugByteCode = false; |
| 50 |
protected String optimizerFlags = "-"; |
| 51 |
protected boolean jitFlag = false; |
| 52 |
protected int streaming = 1; |
| 53 |
protected TreeModel treeModel = TreeModel.TINY_TREE; |
| 54 |
protected boolean debug = false; |
| 55 |
protected boolean export = false; |
| 56 |
protected boolean runWithJS = false; |
| 57 |
protected boolean runWithNodeJS = false; |
| 58 |
protected boolean relocatable = false; |
| 59 |
protected String jsBase = null; |
| 60 |
protected Pattern testPattern = null; |
| 61 |
protected String requestedTestSet = null; |
| 62 |
protected String testSuiteDir; |
| 63 |
protected Processor driverProc = null; |
| 64 |
protected Serializer driverSerializer = null; |
| 65 |
protected HashMap<String, XdmNode> exceptionsMap = new HashMap<String, XdmNode>(); |
| 66 |
protected HashMap<String, String> optimizationAssertions = new HashMap<String, String>(); |
| 67 |
protected Map<String, Environment> globalEnvironments = new HashMap<String, Environment>(); |
| 68 |
protected Map<String, Environment> localEnvironments = new HashMap<String, Environment>(); |
| 69 |
protected Map<String, File> queryModules = new HashMap<String, File>(); |
| 70 |
protected Spec spec; |
| 71 |
protected String lang; |
| 72 |
protected boolean useXslt30Transformer = true; |
| 73 |
protected boolean tracing = false; |
| 74 |
protected boolean isAltova = false; |
| 75 |
protected Map<String, Integer> failSummary = new TreeMap<>(); |
| 76 |
protected boolean quiet = false; |
| 77 |
protected String xxCompilerLocation; |
| 78 |
protected XsltExecutable xxCompiler; |
| 79 |
|
| 80 |
static Set<String> unsharedEnvironments = new HashSet<>(); |
| 81 |
static { |
| 82 |
unsharedEnvironments.add("import-schema-e01"); |
| 83 |
unsharedEnvironments.add("merge002"); |
| 84 |
} |
| 85 |
|
| 86 |
public abstract String catalogNamespace(); |
| 87 |
|
| 88 |
public boolean hasEECapability() { |
| 89 |
return false; |
| 90 |
} |
| 91 |
|
| 92 |
public void go(String[] args) throws Exception { |
| 93 |
|
| 94 |
if (driverProc == null) { |
| 95 |
driverProc = new Processor(false); |
| 96 |
} |
| 97 |
driverSerializer = driverProc.newSerializer(); |
| 98 |
|
| 99 |
System.err.println("Testing " + getProductEdition() + " " + Version.getProductVersion()); |
| 100 |
System.err.println("Java version " + System.getProperty("java.version")); |
| 101 |
|
| 102 |
testSuiteDir = args[0]; |
| 103 |
String catalog = args[1]; |
| 104 |
char separatorChar = '/'; |
| 105 |
if (File.separatorChar != '/') { |
| 106 |
separatorChar = '\\'; |
| 107 |
} |
| 108 |
if(!testSuiteDir.endsWith(""+separatorChar)) { |
| 109 |
testSuiteDir = testSuiteDir + separatorChar; |
| 110 |
} |
| 111 |
catalogFileName = catalog; |
| 112 |
catalog = testSuiteDir+catalog; |
| 113 |
|
| 114 |
for (int i = 2; i < args.length; i++) { |
| 115 |
int colon = args[i].indexOf(':'); |
| 116 |
String argValue = colon < 0 ? "" : args[i].substring(colon+1); |
| 117 |
|
| 118 |
if (args[i].startsWith("-t:")) { |
| 119 |
testPattern = Pattern.compile(argValue); |
| 120 |
} |
| 121 |
if (args[i].startsWith("-s:")) { |
| 122 |
requestedTestSet = argValue; |
| 123 |
} |
| 124 |
if (args[i].equals("-quiet")) { |
| 125 |
quiet = true; |
| 126 |
} |
| 127 |
if (args[i].startsWith("-o:")) { |
| 128 |
resultsDir = argValue; |
| 129 |
} |
| 130 |
if (args[i].startsWith("-debug")) { |
| 131 |
debug = true; |
| 132 |
} |
| 133 |
if (args[i].startsWith("-export") && !argValue.equals("off")) { |
| 134 |
export = true; |
| 135 |
} |
| 136 |
if (args[i].startsWith("-jit") && !argValue.equals("off")) { |
| 137 |
jitFlag = true; |
| 138 |
} |
| 139 |
if (args[i].startsWith("-js")) { |
| 140 |
export = true; |
| 141 |
runWithJS = true; |
| 142 |
treeModel = DOMObjectModel.getInstance(); |
| 143 |
if (args[i].startsWith("-js:") || args[i].startsWith("-js2:")) { |
| 144 |
jsBase = argValue; |
| 145 |
} |
| 146 |
} |
| 147 |
if (args[i].startsWith("-nodeJS")) { |
| 148 |
export = true; |
| 149 |
runWithJS = true; |
| 150 |
runWithNodeJS = true; |
| 151 |
treeModel = DOMObjectModel.getInstance(); |
| 152 |
} |
| 153 |
if (args[i].equals("-unfolded")) { |
| 154 |
unfolded = true; |
| 155 |
} |
| 156 |
if (args[i].equals("-save")) { |
| 157 |
saveResults = true; |
| 158 |
} |
| 159 |
if (args[i].startsWith("-exceptions:")) { |
| 160 |
exceptionsFileName = argValue; |
| 161 |
} |
| 162 |
if (args[i].equals("-T")) { |
| 163 |
tracing = true; |
| 164 |
} |
| 165 |
if (args[i].startsWith("-bytecode:")) { |
| 166 |
switch (argValue) { |
| 167 |
case "on": |
| 168 |
generateByteCode = 0; |
| 169 |
break; |
| 170 |
case "debug": |
| 171 |
debugByteCode = true; |
| 172 |
generateByteCode = 0; |
| 173 |
break; |
| 174 |
case "off": |
| 175 |
generateByteCode = -1; |
| 176 |
|
| 177 |
break; |
| 178 |
default: |
| 179 |
generateByteCode = Integer.parseInt(argValue); |
| 180 |
break; |
| 181 |
} |
| 182 |
} |
| 183 |
if (args[i].startsWith("-streaming:")) { |
| 184 |
switch (argValue) { |
| 185 |
case "off": |
| 186 |
streaming = 0; |
| 187 |
break; |
| 188 |
case "on": |
| 189 |
streaming = 1; |
| 190 |
break; |
| 191 |
case "strict": |
| 192 |
streaming = 3; |
| 193 |
break; |
| 194 |
default: |
| 195 |
throw new Exception("-streaming must be off|on|strict"); |
| 196 |
} |
| 197 |
} |
| 198 |
if (args[i].startsWith("-tree")) { |
| 199 |
treeModel = getTreeModel(argValue); |
| 200 |
if (treeModel == null) { |
| 201 |
throw new Exception("The requested TreeModel '" + argValue + "' does not exist"); |
| 202 |
} |
| 203 |
|
| 204 |
} |
| 205 |
if (args[i].startsWith("-lang:")) { |
| 206 |
lang = argValue; |
| 207 |
processSpec(argValue); |
| 208 |
} |
| 209 |
|
| 210 |
if (args[i].startsWith("-xt30:")) { |
| 211 |
useXslt30Transformer = argValue.equals("on"); |
| 212 |
} |
| 213 |
|
| 214 |
if (args[i].startsWith("-ps:")) { |
| 215 |
runPostureAndSweepTests = argValue.equals("on"); |
| 216 |
} |
| 217 |
|
| 218 |
if (args[i].startsWith("-relocatable:")) { |
| 219 |
relocatable = argValue.equals("on"); |
| 220 |
} |
| 221 |
|
| 222 |
if (args[i].startsWith("-opt:")) { |
| 223 |
optimizerFlags = argValue; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
if (args[i].startsWith("-XX:")) { |
| 228 |
xxCompilerLocation = argValue; |
| 229 |
System.err.println("Using XX compiler at " + xxCompilerLocation); |
| 230 |
} |
| 231 |
} |
| 232 |
if (resultsDoc == null) { |
| 233 |
printError("No result document: missing -lang option", ""); |
| 234 |
if (shell == null) { |
| 235 |
System.exit(2); |
| 236 |
} |
| 237 |
} |
| 238 |
if (resultsDir == null) { |
| 239 |
printError("No results directory specified (use -o:dirname)", ""); |
| 240 |
if (shell == null) { |
| 241 |
System.exit(2); |
| 242 |
} |
| 243 |
} |
| 244 |
|
| 245 |
System.err.println("UsingXslt30Transformer: " + useXslt30Transformer); |
| 246 |
System.err.println("Relocatable: " + relocatable); |
| 247 |
|
| 248 |
driverSerializer.setOutputStream(System.err); |
| 249 |
driverSerializer.setOutputProperty(Serializer.Property.METHOD, "adaptive"); |
| 250 |
driverSerializer.setOutputProperty(Serializer.Property.OMIT_XML_DECLARATION, "yes"); |
| 251 |
driverSerializer.setOutputProperty(Serializer.Property.INDENT, "yes"); |
| 252 |
driverProc.setConfigurationProperty(Feature.STABLE_UNPARSED_TEXT, true); |
| 253 |
processCatalog(new File(catalog)); |
| 254 |
printResults(resultsDir + "/results" + Version.getProductVersion() + ".xml"); |
| 255 |
} |
| 256 |
|
| 257 |
public boolean isDebugByteCode(){ |
| 258 |
return debugByteCode; |
| 259 |
} |
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
protected TreeModel getTreeModel(String s) { |
| 268 |
TreeModel tree = null; |
| 269 |
if (s.equalsIgnoreCase("dom")) { |
| 270 |
tree = new DOMObjectModel(); |
| 271 |
} else if (s.equalsIgnoreCase("tinytree")) { |
| 272 |
tree = TreeModel.TINY_TREE; |
| 273 |
} else if (s.equalsIgnoreCase("condensed")) { |
| 274 |
tree = TreeModel.TINY_TREE_CONDENSED; |
| 275 |
} else if (s.equalsIgnoreCase("linked")) { |
| 276 |
tree = TreeModel.LINKED_TREE; |
| 277 |
} |
| 278 |
return tree; |
| 279 |
} |
| 280 |
|
| 281 |
public XdmNode makeDominoTree(Document doc, Configuration config, String baseUri) throws SaxonApiException { |
| 282 |
throw new UnsupportedOperationException("Domino needs PE+"); |
| 283 |
} |
| 284 |
|
| 285 |
public String getResultsDir() { |
| 286 |
return resultsDir; |
| 287 |
} |
| 288 |
|
| 289 |
public abstract void processSpec(String specStr); |
| 290 |
|
| 291 |
public boolean isByteCode() { |
| 292 |
return generateByteCode == 0; |
| 293 |
} |
| 294 |
|
| 295 |
public String getProductEdition() { |
| 296 |
return "Saxon-" + driverProc.getSaxonEdition(); |
| 297 |
} |
| 298 |
|
| 299 |
public String getProductVersion() { |
| 300 |
return Version.getProductVersion(); |
| 301 |
} |
| 302 |
|
| 303 |
public void prepareForSQL(Processor processor) {} |
| 304 |
|
| 305 |
|
| 306 |
protected void processCatalog(File catalogFile) throws SaxonApiException { |
| 307 |
if (driverProc.getSaxonEdition().equals("EE")) { |
| 308 |
if (generateByteCode == 0 && !debugByteCode) { |
| 309 |
driverProc.setConfigurationProperty(Feature.GENERATE_BYTE_CODE, true); |
| 310 |
driverProc.setConfigurationProperty(Feature.DEBUG_BYTE_CODE, false); |
| 311 |
} else if (generateByteCode >0) { |
| 312 |
driverProc.setConfigurationProperty(FeatureKeys.GENERATE_BYTE_CODE, ""+generateByteCode); |
| 313 |
driverProc.setConfigurationProperty(Feature.DEBUG_BYTE_CODE, false); |
| 314 |
} else if (generateByteCode == 0 && debugByteCode) { |
| 315 |
driverProc.setConfigurationProperty(Feature.GENERATE_BYTE_CODE, true); |
| 316 |
driverProc.setConfigurationProperty(Feature.DEBUG_BYTE_CODE, true); |
| 317 |
} else { |
| 318 |
driverProc.setConfigurationProperty(Feature.GENERATE_BYTE_CODE, false); |
| 319 |
driverProc.setConfigurationProperty(Feature.DEBUG_BYTE_CODE, false); |
| 320 |
} |
| 321 |
} |
| 322 |
DocumentBuilder catbuilder = driverProc.newDocumentBuilder(); |
| 323 |
catbuilder.setTreeModel(treeModel); |
| 324 |
catbuilder.setLineNumbering(true); |
| 325 |
XdmNode catalog = catbuilder.build(catalogFile); |
| 326 |
catalogNode = catalog; |
| 327 |
XPathCompiler xpc = driverProc.newXPathCompiler(); |
| 328 |
xpc.setLanguageVersion("3.1"); |
| 329 |
xpc.setCaching(true); |
| 330 |
xpc.declareNamespace("", catalogNamespace()); |
| 331 |
|
| 332 |
if (requestedTestSet == null) { |
| 333 |
createGlobalEnvironments(catalog, xpc); |
| 334 |
} |
| 335 |
|
| 336 |
try { |
| 337 |
writeResultFilePreamble(driverProc, catalog); |
| 338 |
} catch (Exception e) { |
| 339 |
throw new RuntimeException(e); |
| 340 |
} |
| 341 |
|
| 342 |
readExceptionsFile(); |
| 343 |
|
| 344 |
|
| 345 |
if (requestedTestSet != null) { |
| 346 |
try { |
| 347 |
Predicate<XdmNode> isRequestedTestSet = node -> requestedTestSet.equals(node.attribute("name")); |
| 348 |
Optional<XdmNode> funcSetNode = catalog.select( |
| 349 |
descendant("test-set").where(isRequestedTestSet)).asOptionalNode(); |
| 350 |
if (!funcSetNode.isPresent()) { |
| 351 |
throw new Exception("Test-set " + requestedTestSet + " not found!"); |
| 352 |
} |
| 353 |
processTestSet(catbuilder, xpc, funcSetNode.get()); |
| 354 |
} catch (Exception e1) { |
| 355 |
e1.printStackTrace(); |
| 356 |
} |
| 357 |
} else { |
| 358 |
for (XdmNode testSet : catalog.select(descendant("test-set")).asList()) { |
| 359 |
processTestSet(catbuilder, xpc, testSet); |
| 360 |
} |
| 361 |
} |
| 362 |
try { |
| 363 |
writeResultFilePostamble(); |
| 364 |
} catch (Exception e) { |
| 365 |
e.printStackTrace(); |
| 366 |
} |
| 367 |
|
| 368 |
|
| 369 |
} |
| 370 |
|
| 371 |
protected String getNameOfExceptionsFile() { |
| 372 |
return exceptionsFileName; |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
protected void readExceptionsFile() { |
| 393 |
|
| 394 |
XdmNode exceptionsDoc = null; |
| 395 |
DocumentBuilder exceptBuilder = driverProc.newDocumentBuilder(); |
| 396 |
QName testSet = new QName("", "test-set"); |
| 397 |
QName testCase = new QName("", "test-case"); |
| 398 |
QName run = new QName("", "run"); |
| 399 |
QName edition = new QName("", "edition"); |
| 400 |
String saxonEdition = driverProc.getSaxonEdition(); |
| 401 |
try { |
| 402 |
String suppliedName = getNameOfExceptionsFile(); |
| 403 |
File exceptionsFile; |
| 404 |
if (suppliedName.startsWith("/") || suppliedName.matches("^[a-zA-Z]:.*")) { |
| 405 |
exceptionsFile = new File(suppliedName); |
| 406 |
} else { |
| 407 |
exceptionsFile = new File(resultsDir + "/" + suppliedName); |
| 408 |
} |
| 409 |
System.err.println("Loading exceptions file " + exceptionsFile.getAbsolutePath()); |
| 410 |
exceptionsDoc = exceptBuilder.build(exceptionsFile); |
| 411 |
XdmSequenceIterator iter = exceptionsDoc.axisIterator(Axis.DESCENDANT, new QName("", "exception")); |
| 412 |
while (iter.hasNext()) { |
| 413 |
XdmNode entry = (XdmNode) iter.next(); |
| 414 |
String testName = entry.getAttributeValue(testCase); |
| 415 |
if (testName == null) { |
| 416 |
testName = "$" + entry.getAttributeValue(testSet); |
| 417 |
} |
| 418 |
String runVal = entry.getAttributeValue(run); |
| 419 |
String editionVal = entry.getAttributeValue(edition); |
| 420 |
if (runVal == null) { |
| 421 |
runVal = "false"; |
| 422 |
} |
| 423 |
if (editionVal == null) { |
| 424 |
editionVal = saxonEdition; |
| 425 |
} |
| 426 |
boolean appliesThisEdition = false; |
| 427 |
for (String ed : editionVal.trim().split("\\s+")) { |
| 428 |
if (ed.equals(saxonEdition)) { |
| 429 |
appliesThisEdition = true; |
| 430 |
break; |
| 431 |
} |
| 432 |
} |
| 433 |
if (appliesThisEdition) { |
| 434 |
if (runVal.equals("false")) { |
| 435 |
for (String tc : testName.trim().split("\\s+")) { |
| 436 |
exceptionsMap.put(tc, entry); |
| 437 |
} |
| 438 |
} else { |
| 439 |
XdmSequenceIterator iter2 = entry.axisIterator(Axis.CHILD, new QName("optimization")); |
| 440 |
if (iter2.hasNext()) { |
| 441 |
XdmNode optim = (XdmNode) iter2.next(); |
| 442 |
optimizationAssertions.put(testName, optim.attribute("assert")); |
| 443 |
} |
| 444 |
} |
| 445 |
} |
| 446 |
} |
| 447 |
} catch (SaxonApiException e) { |
| 448 |
printError("*** Failed to process exceptions file: ", e.getMessage()); |
| 449 |
} |
| 450 |
|
| 451 |
} |
| 452 |
|
| 453 |
protected abstract void createGlobalEnvironments( |
| 454 |
XdmNode catalog, XPathCompiler xpc) |
| 455 |
throws SaxonApiException; |
| 456 |
|
| 457 |
protected void createLocalEnvironments(XdmNode testSetDocNode) { |
| 458 |
localEnvironments.clear(); |
| 459 |
Environment defaultEnvironment = |
| 460 |
Environment.createLocalEnvironment(testSetDocNode.getBaseURI(), generateByteCode, unfolded, spec, this); |
| 461 |
localEnvironments.put("default", defaultEnvironment); |
| 462 |
} |
| 463 |
|
| 464 |
protected Environment getEnvironment(XdmNode testCase, XPathCompiler xpc) throws SaxonApiException { |
| 465 |
String testCaseName = testCase.attribute("name"); |
| 466 |
Optional<XdmNode> environmentNode = testCase.select(child("environment")).asOptionalNode(); |
| 467 |
Environment env; |
| 468 |
if (!environmentNode.isPresent()) { |
| 469 |
env = localEnvironments.get("default"); |
| 470 |
} else { |
| 471 |
String envName = environmentNode.get().attribute("ref"); |
| 472 |
if (envName == null || envName.equals("")) { |
| 473 |
boolean baseUriCheck = false; |
| 474 |
env = null; |
| 475 |
try { |
| 476 |
env = Environment.processEnvironment( |
| 477 |
this, xpc, environmentNode.get(), null, localEnvironments.get("default")); |
| 478 |
baseUriCheck = environmentNode.get().select( |
| 479 |
child("static-base-uri").where(attributeEq("uri", "#UNDEFINED"))).exists(); |
| 480 |
} catch (NullPointerException ex) { |
| 481 |
ex.printStackTrace(); |
| 482 |
System.err.println("Failure loading environment"); |
| 483 |
if (env != null) { |
| 484 |
env.usable = false; |
| 485 |
} |
| 486 |
} |
| 487 |
if (baseUriCheck) { |
| 488 |
|
| 489 |
return null; |
| 490 |
} |
| 491 |
} else { |
| 492 |
env = localEnvironments.get(envName); |
| 493 |
if (env == null) { |
| 494 |
env = globalEnvironments.get(envName); |
| 495 |
} |
| 496 |
if (env == null) { |
| 497 |
try { |
| 498 |
for (XdmNode e : testCase.getParent().select(descendant("environment").where(attributeEq("name", envName))).asList()) { |
| 499 |
Environment.processEnvironment(this, xpc, e, localEnvironments, localEnvironments.get("default")); |
| 500 |
} |
| 501 |
env = localEnvironments.get(envName); |
| 502 |
if (unsharedEnvironments.contains(envName)){ |
| 503 |
localEnvironments.remove(envName); |
| 504 |
} |
| 505 |
} catch (NullPointerException ex) { |
| 506 |
ex.printStackTrace(); |
| 507 |
System.err.println("Failure loading environment"); |
| 508 |
if (env != null) { |
| 509 |
env.usable = false; |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
if (env == null) { |
| 514 |
|
| 515 |
|
| 516 |
createGlobalEnvironments(catalogNode, xpc); |
| 517 |
env = globalEnvironments.get(envName); |
| 518 |
} |
| 519 |
if (env == null) { |
| 520 |
println("*** Unknown environment " + envName); |
| 521 |
|
| 522 |
noteFailure(testCase.getParent().attribute("name"), testCaseName); |
| 523 |
return null; |
| 524 |
} |
| 525 |
|
| 526 |
} |
| 527 |
} |
| 528 |
return env; |
| 529 |
} |
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
public void registerXQueryModule(String uri, File resource) { |
| 536 |
queryModules.put(uri, resource); |
| 537 |
} |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
public File exportStylesheet(XsltCompiler compiler, String fileName) throws SaxonApiException { |
| 544 |
return null; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
public void addInjection(XQueryCompiler compiler) { |
| 554 |
|
| 555 |
} |
| 556 |
|
| 557 |
public void noteFailure(String testSet, String testCase) { |
| 558 |
failures++; |
| 559 |
if (requestedTestSet != null) { |
| 560 |
failSummary.put(testCase, 1); |
| 561 |
} else { |
| 562 |
failSummary.merge(testSet, 1, (a, b) -> a + b); |
| 563 |
} |
| 564 |
} |
| 565 |
|
| 566 |
protected void writeResultFilePreamble(Processor processor, XdmNode catalog) |
| 567 |
throws IOException, SaxonApiException, XMLStreamException { |
| 568 |
resultsDoc.writeResultFilePreamble(processor, catalog); |
| 569 |
} |
| 570 |
|
| 571 |
protected void writeResultFilePostamble() |
| 572 |
throws XMLStreamException { |
| 573 |
resultsDoc.writeResultFilePostamble(); |
| 574 |
if (requestedTestSet != null) { |
| 575 |
System.err.println("Failing tests: "); |
| 576 |
for (Map.Entry<String, Integer> entry : failSummary.entrySet()) { |
| 577 |
System.err.println(" " + entry.getKey()); |
| 578 |
} |
| 579 |
} else { |
| 580 |
System.err.println("Failures by Test Set: "); |
| 581 |
for (Map.Entry<String, Integer> entry : failSummary.entrySet()) { |
| 582 |
System.err.println(" " + entry.getKey() + " : " + entry.getValue()); |
| 583 |
} |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
protected void startTestSetElement(XdmNode testSetNode) { |
| 588 |
resultsDoc.startTestSetElement(testSetNode); |
| 589 |
} |
| 590 |
|
| 591 |
protected void writeTestSetEndElement() { |
| 592 |
resultsDoc.endElement(); |
| 593 |
} |
| 594 |
|
| 595 |
|
| 596 |
private void processTestSet(DocumentBuilder catbuilder, XPathCompiler xpc, XdmNode testSetNode) throws SaxonApiException { |
| 597 |
String testName; |
| 598 |
String testSet; |
| 599 |
startTestSetElement(testSetNode); |
| 600 |
File testSetFile = new File(testSuiteDir + "/" + testSetNode.attribute("file")); |
| 601 |
XdmNode testSetDocNode = catbuilder.build(testSetFile); |
| 602 |
createLocalEnvironments(testSetDocNode); |
| 603 |
boolean run = true; |
| 604 |
|
| 605 |
if (testSetDocNode.select(child("test-set").then(child("dependency"))).exists()) { |
| 606 |
for (XdmNode dependency : testSetDocNode.select(child("test-set").then(child("dependency"))).asList()) { |
| 607 |
if (!ensureDependencySatisfied(dependency, localEnvironments.get("default"))) { |
| 608 |
for (XdmNode testCase : testSetDocNode.select(descendant("test-case")).asList()) { |
| 609 |
String testCaseName = testCase.attribute("name"); |
| 610 |
resultsDoc.writeTestcaseElement(testCaseName, "n/a", "test-set dependencies not satisfied"); |
| 611 |
notrun++; |
| 612 |
} |
| 613 |
run = false; |
| 614 |
break; |
| 615 |
} |
| 616 |
} |
| 617 |
} |
| 618 |
|
| 619 |
if (testSetDocNode.select(child("test-set").then(child("dependencies"))).exists()) { |
| 620 |
for (XdmNode dependency : testSetDocNode.select(path("test-set", "dependencies", "*")).asListOfNodes()) { |
| 621 |
if (!ensureDependencySatisfied(dependency, localEnvironments.get("default"))) { |
| 622 |
for (XdmNode testCase : testSetDocNode.select(descendant("test-case")).asList()) { |
| 623 |
String type = dependency.getNodeName().getLocalName(); |
| 624 |
String value = dependency.attribute("value"); |
| 625 |
if (value == null) { |
| 626 |
value = type; |
| 627 |
} else { |
| 628 |
value = type + ":" + value; |
| 629 |
} |
| 630 |
if ("false".equals(dependency.attribute("satisfied"))) { |
| 631 |
value = "!" + value; |
| 632 |
} |
| 633 |
String testCaseName = testCase.attribute("name"); |
| 634 |
resultsDoc.writeTestcaseElement(testCaseName, "n/a", "test-set dependencies not satisfied: " + value); |
| 635 |
notrun++; |
| 636 |
} |
| 637 |
run = false; |
| 638 |
break; |
| 639 |
} |
| 640 |
} |
| 641 |
} |
| 642 |
if (run) { |
| 643 |
if (testPattern == null) { |
| 644 |
for (XdmNode env : testSetDocNode.select(descendant("environment").where(hasAttribute("name"))).asList()) { |
| 645 |
String envName = env.attribute("name"); |
| 646 |
if (!unsharedEnvironments.contains(envName)) { |
| 647 |
try { |
| 648 |
Environment.processEnvironment(this, xpc, env, localEnvironments, localEnvironments.get("default")); |
| 649 |
} catch (NullPointerException ex) { |
| 650 |
ex.printStackTrace(); |
| 651 |
System.err.println("Failure loading environment, in processTestSet"); |
| 652 |
} |
| 653 |
} |
| 654 |
} |
| 655 |
} |
| 656 |
testSet = testSetDocNode.select(Steps.path("/", "test-set", "@name")).collect(asString()); |
| 657 |
testSetDocNode.select(descendant("test-case")).forEach(testCase -> { |
| 658 |
String name = testCase.attribute("name"); |
| 659 |
if (testPattern == null || testPattern.matcher(name).matches()) { |
| 660 |
println("-s:" + testSet + " -t:" + name); |
| 661 |
|
| 662 |
try { |
| 663 |
runTestCase(testCase, xpc); |
| 664 |
} catch (SaxonApiException ex) { |
| 665 |
ex.printStackTrace(); |
| 666 |
System.err.println("*** Error in evaluating testcase:" + ex.getMessage()); |
| 667 |
} |
| 668 |
} |
| 669 |
}); |
| 670 |
} |
| 671 |
writeTestSetEndElement(); |
| 672 |
} |
| 673 |
|
| 674 |
protected abstract void runTestCase(XdmNode testCase, XPathCompiler catalogXpc) |
| 675 |
throws SaxonApiException; |
| 676 |
|
| 677 |
public void setTestDriverShell(TestDriverShell gui) { |
| 678 |
shell = gui; |
| 679 |
} |
| 680 |
|
| 681 |
public void println(String data) { |
| 682 |
if (!quiet) { |
| 683 |
shell.println(data); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
public void printResults(String resultsFileStr) { |
| 688 |
shell.printResults("Result: " + successes + " successes, " + failures + " failures, " + wrongErrorResults + " incorrect ErrorCode, " + notrun + " not run", |
| 689 |
resultsFileStr, resultsDir); |
| 690 |
} |
| 691 |
|
| 692 |
public void printError(String error, String message) { |
| 693 |
shell.alert(error); |
| 694 |
shell.println(error + message); |
| 695 |
} |
| 696 |
|
| 697 |
public void printError(String error, Exception e) { |
| 698 |
shell.alert(error); |
| 699 |
e.printStackTrace(); |
| 700 |
} |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
public abstract boolean ensureDependencySatisfied(XdmNode dependency, Environment env); |
| 715 |
|
| 716 |
|
| 717 |
protected void copySchemaNamespaces(Environment env, XPathCompiler testXpc) { |
| 718 |
Configuration config = env.xpathCompiler.getProcessor().getUnderlyingConfiguration(); |
| 719 |
for (String s : config.getImportedNamespaces()) { |
| 720 |
testXpc.importSchemaNamespace(s); |
| 721 |
} |
| 722 |
} |
| 723 |
|
| 724 |
} |
| 725 |
|