Skip to content

Commit 0a513a9

Browse files
committed
generate.py: disallow generating test suites for multiple paths
Our generate.py script is used to extract and write test suite declarations into the clar.suite file. As is, the script accepts multiple directories on the command line and will generate this file for each of these directories. The generate.py script will always write the clar.suite file into the directory which is about to be scanned. This actually breaks out-of-tree builds with libgit2, as the file will be generated in the source tree instead of in the build tree. This is noticed especially in the case where the source tree is mounted read-only, rendering us unable to build unit tests. Due to us accepting multiple paths which are to be scanned, it is not trivial to fix though. The first solution which comes into mind would be to re-create the directory hierarchy at a given output path or use unique names for the clar.suite files, but this is rather cumbersome and magical. The second and cleaner solution would be to fold all directories into a single clar.suite file, but this would probably break some use-cases. Seeing that we do not ever pass multiple directories to generate.py, we will now simply retire support for this. This allows us to later on introduce an additional option to specify the path where the clar.suite file will be generated at, defaulting to "clar.suite" inside of the scanned directory.
1 parent fa94875 commit 0a513a9

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

tests/generate.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from __future__ import with_statement
1010
from string import Template
11-
import re, fnmatch, os, codecs, pickle
11+
import re, fnmatch, os, sys, codecs, pickle
1212

1313
class Module(object):
1414
class Template(object):
@@ -234,11 +234,14 @@ def write(self):
234234
parser.add_option('-x', '--exclude', dest='excluded', action='append', default=[])
235235

236236
options, args = parser.parse_args()
237-
238-
for path in args or ['.']:
239-
suite = TestSuite(path)
240-
suite.load(options.force)
241-
suite.disable(options.excluded)
242-
if suite.write():
243-
print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
237+
if len(args) > 1:
238+
print("More than one path given")
239+
sys.exit(1)
240+
241+
path = args.pop() if args else '.'
242+
suite = TestSuite(path)
243+
suite.load(options.force)
244+
suite.disable(options.excluded)
245+
if suite.write():
246+
print("Written `clar.suite` (%d tests in %d suites)" % (suite.callback_count(), suite.suite_count()))
244247

0 commit comments

Comments
 (0)