Skip to content

Commit f52c874

Browse files
author
akaranta
committed
added automatic scanning of tests folder for tests + some some simple tests for c funcs
git-svn-id: https://svn.codehaus.org/groovy/trunk/groovy/modules/native_launcher@20331 a5544e8c-8a19-0410-ba12-f9af4593a198
1 parent f3fa424 commit f52c874

7 files changed

+109
-13
lines changed

nativelaunchertester.py

+23-9
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import os
2121
import sys
22+
import re
2223

2324
class NativeLauncherTester :
2425

@@ -46,16 +47,29 @@ def runLauncherTests ( self, target , source , env ) :
4647

4748
if testModuleName in alreadyExecuted : continue
4849

49-
try :
50-
module = __import__ ( testModuleName )
51-
except ImportError , ie :
52-
print 'Error loading tests for ' , root, ' :: ' , ie
50+
if self.runSingleTest( testModuleName, env, item ) :
5351
testsFailed = True
54-
else :
55-
print 'Running test ' , testModuleName
56-
if not module.runTests ( item.path , env[ 'PLATFORM' ] ) :
57-
print ' Tests failed.'
58-
testsFailed = True
5952

6053
alreadyExecuted.append( testModuleName )
6154
print
55+
56+
for testfile in os.listdir( 'tests' ) :
57+
testModuleName = re.sub( '\.py\Z', '', testfile )
58+
if testModuleName in alreadyExecuted or not re.search( 'Test\Z', testModuleName ) : continue
59+
if self.runSingleTest( testModuleName, env ) :
60+
testsFailed = True
61+
62+
def runSingleTest( self, testModuleName, env, item = None ) :
63+
testFailed = False
64+
try :
65+
module = __import__ ( testModuleName )
66+
except ImportError , ie :
67+
print 'Error loading test file ' , testModuleName, ' :: ' , ie
68+
testFailed = True
69+
else :
70+
print 'Running test ' , testModuleName
71+
if not module.runTests ( item.path if item else None, env[ 'PLATFORM' ] ) :
72+
print ' Tests failed.'
73+
testsFailed = True
74+
return testFailed
75+

source/jst_fileutils.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,14 @@ static void changeEmptyPrefixAndSuffixToNULL( char** fileNamePrefix, char** file
224224

225225
}
226226

227-
#else
227+
#endif
228228

229-
extern int matchPrefixAndSuffixToFileName( char* fileName, char* prefix, char* suffix ) {
229+
extern int matchPrefixAndSuffixToFileName( const char* fileName, const char* prefix, const char* suffix ) {
230230

231231
return jst_startsWith( fileName, prefix ) && jst_endsWith( fileName, suffix ) ;
232232

233233
}
234234

235-
#endif
236235

237236

238237
#if defined( _WIN32 )

source/jst_fileutils.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jboolean jst_dirNameEndsWithSeparator( const char* dirName ) ;
105105

106106
/** Checks that the given file name has the given prefix and suffix. Give NULL to match anything. fileName may not be NULL.
107107
* Returns true if the given prefix and suffix match. */
108-
int matchPrefixAndSuffixToFileName( char* fileName, char* prefix, char* suffix ) ;
108+
int matchPrefixAndSuffixToFileName( const char* fileName, const char* prefix, const char* suffix ) ;
109109

110110
/** a simple validator func that can be used as an argument to some other funcs that take a corresponding
111111
* function pointer as a parameter */

source/nativelauncher.i

+4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@
3535
%{
3636
#include "jvmstarter.h"
3737
#include "groovyutils.h"
38+
#include "jst_stringutils.h"
39+
#include "jst_fileutils.h"
3840
%}
3941

4042
%include "jvmstarter.h"
4143
%include "groovyutils.h"
44+
%include "jst_stringutils.h"
45+
%include "jst_fileutils.h"
4246

4347

4448

tests/FileUtilsTest.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- mode:python; coding:utf-8; -*-
2+
# jedit: :mode=python:
3+
4+
# Copyright � 2010 Antti Karanta
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
7+
# compliance with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed under the License is
12+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
# implied. See the License for the specific language governing permissions and limitations under the
14+
# License.
15+
16+
import unittest
17+
18+
import supportModule
19+
import nativelauncher
20+
21+
22+
class FileUtilsTestCase ( unittest.TestCase ) :
23+
24+
def testFileExists( self ) :
25+
self.assertTrue( nativelauncher.jst_fileExists( __file__ ) )
26+
self.assertFalse( nativelauncher.jst_fileExists( __file__ + '.not' ) )
27+
28+
def testMatchPrefixAndSuffixToFileName( self ) :
29+
self.assertTrue( nativelauncher.matchPrefixAndSuffixToFileName( 'hello.txt', 'hel', '.txt' ) )
30+
self.assertTrue( nativelauncher.matchPrefixAndSuffixToFileName( 'hello.txt', '', '.txt' ) )
31+
self.assertTrue( nativelauncher.matchPrefixAndSuffixToFileName( 'hello.txt', 'hel', '' ) )
32+
33+
def runTests ( path , architecture ) :
34+
return supportModule.runTests ( path , architecture , FileUtilsTestCase )
35+
36+
if __name__ == '__main__' :
37+
print 'Run tests using command "scons test".'

tests/StringUtilsTest.py

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# -*- mode:python; coding:utf-8; -*-
2+
# jedit: :mode=python:
3+
4+
# Copyright � 2010 Antti Karanta
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
7+
# compliance with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software distributed under the License is
12+
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
# implied. See the License for the specific language governing permissions and limitations under the
14+
# License.
15+
16+
import unittest
17+
18+
import supportModule
19+
import nativelauncher
20+
21+
22+
class StringUtilsTestCase ( unittest.TestCase ) :
23+
24+
def testStartsWith( self ) :
25+
self.assertTrue( nativelauncher.jst_startsWith( 'foobar', 'foo' ) )
26+
self.assertTrue( nativelauncher.jst_startsWith( 'foobar', '' ) )
27+
self.assertFalse( nativelauncher.jst_startsWith( 'foobar', 'bar' ) )
28+
29+
def testEndsWith( self ) :
30+
self.assertFalse( nativelauncher.jst_endsWith( 'foobar', 'foo' ) )
31+
self.assertTrue( nativelauncher.jst_endsWith( 'foobar', '' ) )
32+
self.assertTrue( nativelauncher.jst_endsWith( 'foobar', 'bar' ) )
33+
34+
35+
def runTests ( path , architecture ) :
36+
return supportModule.runTests ( path , architecture , StringUtilsTestCase )
37+
38+
if __name__ == '__main__' :
39+
print 'Run tests using command "scons test".'

tests/supportModule.py

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def runTests ( path , architecture , testClass ) :
5454
executablePath = path
5555
global platform
5656
platform = architecture
57+
return runTestsInClass( testClass )
58+
59+
def runTestsInClass( testClass ) :
5760
if os.environ['xmlOutputRequired'] == 'True' :
5861
resultsDirectory = os.environ['xmlTestOutputDirectory']
5962
if not os.path.exists ( resultsDirectory ) : os.mkdir ( resultsDirectory )

0 commit comments

Comments
 (0)