Import('env')
Import('pdb2pqr')
import sys
import os

AddOption('--long-test-count',
        dest='longTestCount',
        action='store',
        type=int,
        help='When building the long-test target specify how many tests to run.')

commandLineStart = sys.executable + ' ' + str(pdb2pqr[0])
nullTarget = '/dev/null'    
if os.name == 'nt':
    nullTarget = 'nul'
    
testList = []
testParams = []
with open('lst') as f:
    for inName in f.readlines():
    	name = inName.strip()
    	testParams.append((name,'out/'+name+'.pqr','out/'+name+'.std','out/'+name+'.err'))
        
testCount = GetOption('longTestCount')
if not GetOption("clean") and testCount is not None and testCount > 0:
    testParams = testParams[:testCount]
    
#Long Test
for param in testParams:
    testCommand = commandLineStart + ' --verbose --ff=PARSE %s ${TARGETS[0]} 1>${TARGETS[1]} 2>${TARGETS[2]}' % param[0]
    runTest = env.Command([param[1],param[2],param[3]], 'lst', testCommand)

    if GetOption("clean"):
        env.Default(runTest)
    else:
        Depends(runTest, DEFAULT_TARGETS)
    
    AlwaysBuild(runTest)
    testList.append(runTest)

Alias('long-test', testList )
