1
0
Fork 0

execute examples in their complete alphabetical order, regardles of whether they're OUTPUT or RUN

This commit is contained in:
Willi Goesgens 2015-08-11 14:13:53 +02:00
parent 25024d7935
commit 76dbe1b8cf
1 changed files with 109 additions and 80 deletions

View File

@ -63,7 +63,7 @@ OutputDir = "/tmp/"
### commands and there output is logged. ### commands and there output is logged.
################################################################################ ################################################################################
ArangoshOutput = {} RunTests = {}
################################################################################ ################################################################################
### @brief arangosh expect ### @brief arangosh expect
@ -73,16 +73,6 @@ ArangoshOutput = {}
ArangoshExpect = {} ArangoshExpect = {}
################################################################################
### @brief arangosh run
###
### A list of commands that are executed in order to produce the output. This
### is mostly used for HTTP request examples.
################################################################################
ArangoshRun = {}
################################################################################ ################################################################################
### @brief arangosh run ### @brief arangosh run
### ###
@ -102,11 +92,6 @@ ArangoshFiles = {}
MapSourceFiles = {} MapSourceFiles = {}
################################################################################
### @brief arangosh examples, in some deterministic order
################################################################################
ArangoshCases = [ ]
################################################################################ ################################################################################
### @brief global setup for arangosh ### @brief global setup for arangosh
################################################################################ ################################################################################
@ -124,8 +109,8 @@ FilterForTestcase = None
################################################################################ ################################################################################
STATE_BEGIN = 0 STATE_BEGIN = 0
STATE_ARANGOSH_OUTPUT = 1 STATE_ARANGOSH_OUTPUT = 'HTTP_LOUTPUT'
STATE_ARANGOSH_RUN = 2 STATE_ARANGOSH_RUN = 'ARANGOSH_OUTPUT'
################################################################################ ################################################################################
### @brief option states ### @brief option states
@ -182,6 +167,9 @@ var curlRequest = function () {
}; };
var logJsonResponse = internal.appendJsonResponse(appender); var logJsonResponse = internal.appendJsonResponse(appender);
var logRawResponse = internal.appendRawResponse(appender); var logRawResponse = internal.appendRawResponse(appender);
var logErrorResponse = function (response) {
allErrors += "Server reply was: " + JSON.stringify(response) + "\\n";
};
var globalAssert = function(condition, testname, sourceFile) { var globalAssert = function(condition, testname, sourceFile) {
if (! condition) { if (! condition) {
internal.output(hashes + '\\nASSERTION FAILED: ' + testname + ' in file ' + sourceFile + '\\n' + hashes + '\\n'); internal.output(hashes + '\\nASSERTION FAILED: ' + testname + ' in file ' + sourceFile + '\\n' + hashes + '\\n');
@ -346,8 +334,6 @@ def matchStartLine(line, filename):
print >> sys.stderr, "filtering test case %s" %name print >> sys.stderr, "filtering test case %s" %name
return("", STATE_BEGIN); return("", STATE_BEGIN);
ArangoshFiles[name] = True
ArangoshOutput[name] = []
return (name, STATE_ARANGOSH_OUTPUT) return (name, STATE_ARANGOSH_OUTPUT)
m = runLine.match(line) m = runLine.match(line)
@ -365,9 +351,7 @@ def matchStartLine(line, filename):
print >> sys.stderr, "filtering test case %s" %name print >> sys.stderr, "filtering test case %s" %name
return("", STATE_BEGIN); return("", STATE_BEGIN);
ArangoshCases.append(name)
ArangoshFiles[name] = True ArangoshFiles[name] = True
ArangoshRun[name] = ""
return (name, STATE_ARANGOSH_RUN) return (name, STATE_ARANGOSH_RUN)
# Not found, remain in STATE_BEGIN # Not found, remain in STATE_BEGIN
return ("", STATE_BEGIN) return ("", STATE_BEGIN)
@ -375,10 +359,15 @@ def matchStartLine(line, filename):
endExample = re.compile(r'^(/// )? *@END_EXAMPLE_') endExample = re.compile(r'^(/// )? *@END_EXAMPLE_')
#r5 = re.compile(r'^ +') #r5 = re.compile(r'^ +')
TESTLINES="testlines"
TYPE="type"
LINE_NO="lineNo"
STRING="string"
################################################################################ ################################################################################
### @brief loop over the lines of one input file ### @brief loop over the lines of one input file
################################################################################ ################################################################################
def analyzeFile(f, filename): def analyzeFile(f, filename):
global RunTests, TESTLINES, TYPE, LINE_NO, STRING
strip = None strip = None
name = "" name = ""
@ -402,8 +391,13 @@ def analyzeFile(f, filename):
(name, state) = matchStartLine(line, filename) (name, state) = matchStartLine(line, filename)
if state != STATE_BEGIN: if state != STATE_BEGIN:
MapSourceFiles[name] = filename MapSourceFiles[name] = filename
RunTests[name] = {}
RunTests[name][TYPE] = state
RunTests[name][TESTLINES] = []
if state == STATE_ARANGOSH_RUN: if state == STATE_ARANGOSH_RUN:
ArangoshRunLineNo[name] = lineNo RunTests[name][LINE_NO] = lineNo;
RunTests[name][STRING] = "";
continue continue
# we are within a example # we are within a example
@ -453,12 +447,15 @@ def analyzeFile(f, filename):
partialLine = "" partialLine = ""
if state == STATE_ARANGOSH_OUTPUT: if state == STATE_ARANGOSH_OUTPUT:
ArangoshOutput[name].append([line, showCmd, lineNo]) RunTests[name][TESTLINES].append([line, showCmd, lineNo])
elif state == STATE_ARANGOSH_RUN: elif state == STATE_ARANGOSH_RUN:
ArangoshRun[name] += line + "\n" RunTests[name][STRING] += line + "\n"
def generateSetupFunction():
print
print "(function () {\n%s}());" % ArangoshSetup
print
################################################################################ ################################################################################
@ -468,18 +465,17 @@ def analyzeFile(f, filename):
loopDetectRE = re.compile(r'^[ \n]*(while|if|var|throw|for) ') loopDetectRE = re.compile(r'^[ \n]*(while|if|var|throw|for) ')
expectErrorRE = re.compile(r'.*// *xpError\((.*)\).*') expectErrorRE = re.compile(r'.*// *xpError\((.*)\).*')
#expectErrorRE = re.compile(r'.*//\s*xpError\(([^)]*)\)/') #expectErrorRE = re.compile(r'.*//\s*xpError\(([^)]*)\)/')
def generateArangoshOutput(): def generateArangoshOutput(testName):
print value = RunTests[testName]
print "(function () {\n%s}());" % ArangoshSetup #print value
print #print value[TESTLINES][0][2]
keys = ArangoshOutput.keys() #print type(value[TESTLINES][0][2])
keys.sort() if (len(value[TESTLINES]) == 0) or (len(value[TESTLINES][0]) < 3):
for key in keys: print "blarg in " + testName
value = ArangoshOutput[key] raise
#print value try:
#print value[0][2]
print ''' print '''
//////////////////////////////////////////////////////////////////////////////// %s
/// %s /// %s
(function() { (function() {
countErrors = 0; countErrors = 0;
@ -490,32 +486,46 @@ def generateArangoshOutput():
var sourceFile = '%s'; var sourceFile = '%s';
var startTime = time(); var startTime = time();
internal.startCaptureMode(); internal.startCaptureMode();
''' %(key, key, value[0][2], OutputDir, MapSourceFiles[key]) ''' % (
for l in value: ('/'*80),
# try to match for errors, and remove the comment. testName,
expectError = 'undefined' testName,
m = expectErrorRE.match(l[0]) value[TESTLINES][0][2],
if m: OutputDir,
expectError = "'" + m.group(1) + "'" MapSourceFiles[testName]
l[0] = l[0][0:l[0].find('//')].rstrip(' ') )
except Exception as x:
print x
print testName
print value
raise
m = loopDetectRE.match(l[0]) for l in value[TESTLINES]:
fakeVar = 'false' # try to match for errors, and remove the comment.
if m and l[0][0:3] == 'var': expectError = 'undefined'
count = l[0].find('=') m = expectErrorRE.match(l[0])
print " " + l[0][0:count].rstrip(' ') + ";" if m:
l[0] = l[0][4:] expectError = "'" + m.group(1) + "'"
fakeVar = 'true' l[0] = l[0][0:l[0].find('//')].rstrip(' ')
m = loopDetectRE.match(l[0])
fakeVar = 'false'
if m and l[0][0:3] == 'var':
count = l[0].find('=')
print " " + l[0][0:count].rstrip(' ') + ";"
l[0] = l[0][4:]
fakeVar = 'true'
print " runTestLine('%s', testName, sourceFile, %s, lineCount++, %s, %s, %s, %s);" % (
l[0], # the test string
l[2], # line in the source file
'true' if l[1] else 'false', # Is it visible in the documentation?
expectError, # will it throw? if the errorcode else undefined.
'true' if m else 'false', # is it a loop construct? (will be evaluated different)
fakeVar # 'var ' should be printed
)
print ''' var output = internal.stopCaptureMode();
print " runTestLine('%s', testName, sourceFile, %s, lineCount++, %s, %s, %s, %s);" % (
l[0], # the test string
l[2], # line in the source file
'true' if l[1] else 'false', # Is it visible in the documentation?
expectError, # will it throw? if the errorcode else undefined.
'true' if m else 'false', # is it a loop construct? (will be evaluated different)
fakeVar # 'var ' should be printed
)
print ''' var output = internal.stopCaptureMode();
print("[" + (time () - startTime) + "s] done with " + testName); print("[" + (time () - startTime) + "s] done with " + testName);
fs.write(outputDir + '/' + testName + '.generated', output); fs.write(outputDir + '/' + testName + '.generated', output);
checkForOrphanTestCollections('not all collections were cleaned up after ' + sourceFile + ' Line[' + startLineCount + '] [' + testName + ']:'); checkForOrphanTestCollections('not all collections were cleaned up after ' + sourceFile + ' Line[' + startLineCount + '] [' + testName + ']:');
@ -527,20 +537,17 @@ def generateArangoshOutput():
### @brief generate arangosh run ### @brief generate arangosh run
################################################################################ ################################################################################
def generateArangoshRun(): def generateArangoshRun(testName):
if JS_DEBUG: if JS_DEBUG:
print "internal.output('%s\\n');" % ('=' * 80) print "internal.output('%s\\n');" % ('=' * 80)
print "internal.output('ARANGOSH RUN\\n');" print "internal.output('ARANGOSH RUN\\n');"
print "internal.output('%s\\n');" % ('=' * 80) print "internal.output('%s\\n');" % ('=' * 80)
print value = RunTests[testName]
print "(function () {\n%s}());" % ArangoshSetup startLineNo = RunTests[testName][LINE_NO]
print print '''
for key in ArangoshCases: %s
value = ArangoshRun[key]
print '''
////////////////////////////////////////////////////////////////////////////////
/// %s /// %s
(function() { (function() {
var ArangoshRun = {}; var ArangoshRun = {};
@ -556,14 +563,24 @@ def generateArangoshRun():
var assert = function(a) { globalAssert(a, testName, sourceFile); }; var assert = function(a) { globalAssert(a, testName, sourceFile); };
testFunc = function() { testFunc = function() {
%s}; %s};
''' %(key, key, ArangoshRunLineNo[key], OutputDir, MapSourceFiles[key], value.lstrip().rstrip()) ''' % (
('/'*80),
testName,
testName,
startLineNo,
OutputDir,
MapSourceFiles[testName],
value[STRING].lstrip().rstrip())
if key in ArangoshExpect: if testName in ArangoshExpect:
print " rc = runTestFuncCatch(testFunc, testName, errors.%s);" % (ArangoshExpect[key]) print " rc = runTestFuncCatch(testFunc, testName, errors.%s);" % (ArangoshExpect[key])
else: else:
print " rc = runTestFunc(testFunc, testName, sourceFile);" print " rc = runTestFunc(testFunc, testName, sourceFile);"
print ''' print '''
if (rc === undefined || rc === '' ) {
rc = " FAILED in " + testName;
}
print("[" + (time () - startTime) + "s] " + rc); print("[" + (time () - startTime) + "s] " + rc);
fs.write(outputDir + '/' + testName + '.generated', output); fs.write(outputDir + '/' + testName + '.generated', output);
checkForOrphanTestCollections('not all collections were cleaned up after ' + sourceFile + ' Line[' + startLineCount + '] [' + testName + ']:'); checkForOrphanTestCollections('not all collections were cleaned up after ' + sourceFile + ' Line[' + startLineCount + '] [' + testName + ']:');
@ -610,12 +627,11 @@ def loopDirectories():
filenames.append(os.path.join(root, file)) filenames.append(os.path.join(root, file))
else: else:
filenames.append(filename) filenames.append(filename)
elif fstate == OPTION_FILTER: elif fstate == OPTION_FILTER:
fstate = OPTION_NORMAL fstate = OPTION_NORMAL
if (len(filename) > 0): if (len(filename) > 0):
FilterForTestcase = re.compile(filename); FilterForTestcase = re.compile(filename);
print dir(FilterForTestcase)
elif fstate == OPTION_ARANGOSH_SETUP: elif fstate == OPTION_ARANGOSH_SETUP:
fstate = OPTION_NORMAL fstate = OPTION_NORMAL
f = open(filename, "r") f = open(filename, "r")
@ -625,7 +641,7 @@ def loopDirectories():
ArangoshSetup += line + "\n" ArangoshSetup += line + "\n"
f.close() f.close()
elif fstate == OPTION_OUTPUT_DIR: elif fstate == OPTION_OUTPUT_DIR:
fstate = OPTION_NORMAL fstate = OPTION_NORMAL
OutputDir = filename OutputDir = filename
@ -640,11 +656,24 @@ def loopDirectories():
print >> sys.stderr, "skipping %s\n" % (filename) print >> sys.stderr, "skipping %s\n" % (filename)
def generateTestCases():
global TESTLINES, TYPE, LINE_NO, STRING, RunTests
testNames = RunTests.keys()
testNames.sort()
for thisTest in testNames:
if RunTests[thisTest][TYPE] == STATE_ARANGOSH_OUTPUT:
generateArangoshOutput(thisTest)
elif RunTests[thisTest][TYPE] == STATE_ARANGOSH_RUN:
generateArangoshRun(thisTest)
################################################################################ ################################################################################
### @brief main ### @brief main
################################################################################ ################################################################################
loopDirectories() loopDirectories()
generateArangoshHeader() generateArangoshHeader()
generateArangoshOutput() generateSetupFunction()
generateArangoshRun() generateTestCases()
generateArangoshShutdown() generateArangoshShutdown()