#!/usr/bin/python
Import('env')
import sys, os, glob

def scanFiles(pattern, paths) :
	files = []
	for path in paths :
		files+=glob.glob(os.path.join(path,pattern))
	return files

def recursiveDirs(root) :
	return filter( (lambda a : a.rfind( ".svn")==-1 ),  [ a[0] for a in os.walk(root)]  )

def unique(list) :
	return dict.fromkeys(list).keys()

folders = [
	os.path.join('.'),
	os.path.join('CommonHelpers'),
	os.path.join('ControlsTests'),
	os.path.join('DescriptorsTests'),
	os.path.join('DynamicTypeTests'),
	os.path.join('FactoryTest'),
	os.path.join('FlowControlTests'),
	os.path.join('NonComponentData'),
	os.path.join('PortsTest'),
	os.path.join('ProcessingBaseTests'),
	os.path.join('ProcessingDataTests'),
	os.path.join('ProcessingsTests'),
	os.path.join('StandardTests'),
	os.path.join('TonalAnalysis'),
	os.path.join('ToolsTests'),
	os.path.join('XmlTests'),
	os.path.join('VisualizationTests'),
	]

blacklist = [
	os.path.join('.','TestRunnerQt.cxx'),
	os.path.join('FactoryTest','PolymorphicTest.cxx'),
	os.path.join('ProcessingsTests','AudioMixerTest.cxx'), # Uses old fashioned idioms that don't compil
	os.path.join('TonalAnalysis','ChordCorrelatorTest.cxx'), # recognized labels not the current ones
	os.path.join('TonalAnalysis','ChordExtractorTest.cxx'), # last too long
	os.path.join('DescriptorsTests','ProofOfConceptTest.cxx'), # Fails always because FFT size, should be rewritten and moved to functional tests
	]
if 'crossmingw' in env['TOOLS'] :
	# They lauch exceptions unsuported in crossmingw until upgrade
	blacklist += [
	os.path.join('DescriptorsTests','DescriptionXmlTest.cxx'),
	os.path.join('DescriptorsTests','SpectralDescriptorsTest.cxx'),
	os.path.join('DescriptorsTests','SpectralPeakDescriptorsTest.cxx'),
	os.path.join('ProcessingBaseTests','ProcessingTest.cxx'), # this one just don't notice the exception
	os.path.join('NonComponentData','FlagsTest.cxx'),
	os.path.join('FlowControlTests','NetworkTest.cxx'),
	os.path.join('DynamicTypeTests','DynamicTypeBasicTest.cxx'),
	os.path.join('XmlTests','LibXmlDomDocumentHandlerTest.cxx'),
	os.path.join('XmlTests','LibXmlDomReaderTest.cxx'),
	os.path.join('XmlTests','XercesDom2ClamObjectsTest.cxx'),
	]


#folders = [ os.path.join('..','..','..','test', folder) for folder in folders ]
#blacklist = [ os.path.join('..','..','..','test', blacksheep) for blacksheep in blacklist ]
sources = scanFiles('*.cxx', folders)
headers = scanFiles('*.hxx', folders)
for blacksheep in blacklist :
	sources.remove(blacksheep) 


unit_tests = env.Program( 'UnitTests', sources )
test_alias = Alias( 'run_unit_tests', [unit_tests], unit_tests[0].abspath )
AlwaysBuild( test_alias )

# Workaround to have only some unit-tests in a separate executable
#simple_test = [ 'TestRunnerConsole.cxx',
                #'TypedControlsTests/TypedControlsTests.cxx' ]
#simple_unit_tests = env.Program( 'simpleUnitTest', simple_test )
#simple_unit_tests_alias = Alias( 'simple_unit_tests', [simple_unit_tests], simple_unit_tests[0].abspath )
#AlwaysBuild( simple_unit_tests )
