Can run unit tests with Ninja.

pull/15/head
Jussi Pakkanen 12 years ago
parent 6a627c6176
commit 277321ecce
  1. 38
      builder_test.py
  2. 2
      environment.py
  3. 18
      generators.py

@ -0,0 +1,38 @@
#!/usr/bin/python3 -tt
# Copyright 2013 Jussi Pakkanen
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys, subprocess
def run_tests(datafilename):
for line in open(datafilename, 'r'):
line = line.strip()
if line == '':
continue
p = subprocess.Popen(line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdo, stde) = p.communicate()
if p.returncode != 0:
print('Error running test.')
print('Stdout:\n' + stdo)
print('Stderr:\n' + stde)
sys.exit(1)
print('Test "%s": OK' % line)
if __name__ == '__main__':
if len(sys.argv) != 2:
print('Test runner for builder. Do not run on your own, mmm\'kay?')
print('%s [data file]' % sys.argv[0])
datafile = sys.argv[1]
run_tests(datafile)

@ -144,7 +144,7 @@ class GnuCXXCompiler(CXXCompiler):
class ArLinker():
std_flags = ['csr']
def __init__(self, exelist):
self.exelist = exelist

@ -148,8 +148,22 @@ class NinjaGenerator(Generator):
self.generate_rules(outfile)
outfile.write('# Build rules for targets\n\n')
[self.generate_target(t, outfile) for t in self.build.get_targets().values()]
outfile.write('# Test rules\n\n')
self.generate_tests(outfile)
outfile.write('# Suffix\n\n')
self.generate_ending(outfile)
def generate_tests(self, outfile):
script_root = '..' # FIXME
test_script = os.path.join(script_root, 'builder_test.py')
test_data = os.path.join(self.environment.get_scratch_dir(), 'builder_test_setup.dat')
outfile.write('build test: CUSTOM_COMMAND\n')
outfile.write(' COMMAND = \'%s\' \'%s\'\n\n' % (ninja_quote(test_script), ninja_quote(test_data)))
datafile = open(test_data, 'w')
for t in self.build.get_tests():
datafile.write(self.get_target_filename(t.get_exe()) + '\n')
datafile.close()
def generate_rules(self, outfile):
outfile.write('# Rules for compiling.\n\n')
@ -157,6 +171,10 @@ class NinjaGenerator(Generator):
outfile.write('# Rules for linking.\n\n')
self.generate_static_link_rules(outfile)
self.generate_dynamic_link_rules(outfile)
outfile.write('# Other rules\n\n')
outfile.write('rule CUSTOM_COMMAND\n')
outfile.write(' command = $COMMAND\n')
outfile.write(' restat = 1\n\n')
def generate_static_link_rules(self, outfile):
static_linker = self.build.static_linker

Loading…
Cancel
Save