Added unit test for rewriter.

pull/1103/head
Jussi Pakkanen 8 years ago
parent d2802a595b
commit 2168860a1e
  1. 42
      run_unittests.py
  2. 5
      test cases/rewrite/1 basic/added.txt
  3. 5
      test cases/rewrite/1 basic/meson.build
  4. 5
      test cases/rewrite/1 basic/removed.txt

@ -17,6 +17,7 @@ import unittest, os, sys, shutil, time
import subprocess import subprocess
import re, json import re, json
import tempfile import tempfile
from glob import glob
import mesonbuild.environment import mesonbuild.environment
from mesonbuild.environment import detect_ninja from mesonbuild.environment import detect_ninja
from mesonbuild.dependencies import PkgConfigDependency, Qt5Dependency from mesonbuild.dependencies import PkgConfigDependency, Qt5Dependency
@ -203,5 +204,46 @@ class LinuxlikeTests(unittest.TestCase):
mesonlog = self.get_meson_log() mesonlog = self.get_meson_log()
self.assertTrue(msg in mesonlog) self.assertTrue(msg in mesonlog)
class RewriterTests(unittest.TestCase):
def setUp(self):
super().setUp()
src_root = os.path.dirname(__file__)
self.testroot = tempfile.mkdtemp()
self.rewrite_command = [sys.executable, os.path.join(src_root, 'mesonast.py')]
self.builddir = tempfile.mkdtemp()
self.test_dir = os.path.join(src_root, 'test cases/rewrite')
def tearDown(self):
shutil.rmtree(self.builddir)
def check_effectively_same(self, mainfile, truth):
with open(os.path.join(self.builddir, mainfile)) as f:
mf = f.read()
with open(os.path.join(self.builddir, truth)) as f:
t = f.read()
# Rewriting is not guaranteed to do a perfect job of
# maintaining whitespace.
self.assertEqual(mf.replace(' ', ''), t.replace(' ', ''))
def test_basic(self):
for f in glob(os.path.join(self.test_dir, '1 basic/*')):
shutil.copy(f, self.builddir)
subprocess.check_call(self.rewrite_command + ['remove',
'--target=trivialprog',
'--filename=notthere.c',
'--sourcedir', self.builddir])
self.check_effectively_same('meson.build', 'removed.txt')
subprocess.check_call(self.rewrite_command + ['add',
'--target=trivialprog',
'--filename=notthere.c',
'--sourcedir', self.builddir])
self.check_effectively_same('meson.build', 'added.txt')
subprocess.check_call(self.rewrite_command + ['remove',
'--target=trivialprog',
'--filename=notthere.c',
'--sourcedir', self.builddir])
self.check_effectively_same('meson.build', 'removed.txt')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

@ -0,0 +1,5 @@
project('rewritetest', 'c')
sources = ['trivial.c']
exe = executable('trivialprog', 'notthere.c', sources)

@ -0,0 +1,5 @@
project('rewritetest', 'c')
sources = ['trivial.c', 'notthere.c']
exe = executable('trivialprog', sources)

@ -0,0 +1,5 @@
project('rewritetest', 'c')
sources = ['trivial.c']
exe = executable('trivialprog', sources)
Loading…
Cancel
Save