run_unittests: use textwrap.dedent

So that editors that can fold code (vim, vscode, etc) can correctly fold
functions, instead of getting confused by code that doesn't follow the
current indention. Also, it makes the code easier to read.
pull/7843/head
Dylan Baker 4 years ago
parent 505f824cf1
commit 5c74cccbb9
  1. 9
      mesonbuild/build.py
  2. 51
      run_unittests.py
  3. 2
      test cases/failing/76 link with shared module on osx/test.json

@ -1359,11 +1359,12 @@ You probably should put it in link_with instead.''')
for link_target in self.link_targets: for link_target in self.link_targets:
if isinstance(link_target, SharedModule): if isinstance(link_target, SharedModule):
if self.environment.machines[self.for_machine].is_darwin(): if self.environment.machines[self.for_machine].is_darwin():
raise MesonException('''target links against shared modules. raise MesonException(
This is not permitted on OSX''') 'target links against shared modules. This is not permitted on OSX')
else: else:
mlog.warning('''target links against shared modules. This is not mlog.warning('target links against shared modules. This '
recommended as it is not supported on some platforms''') 'is not recommended as it is not supported on some '
'platforms')
return return
class Generator: class Generator:

@ -2943,20 +2943,22 @@ class AllPlatformTests(BasePlatformTests):
# the source tree leads to all kinds of trouble. # the source tree leads to all kinds of trouble.
with tempfile.TemporaryDirectory() as project_dir: with tempfile.TemporaryDirectory() as project_dir:
with open(os.path.join(project_dir, 'meson.build'), 'w') as ofile: with open(os.path.join(project_dir, 'meson.build'), 'w') as ofile:
ofile.write('''project('disttest', 'c', version : '1.4.3') ofile.write(textwrap.dedent('''\
e = executable('distexe', 'distexe.c') project('disttest', 'c', version : '1.4.3')
test('dist test', e) e = executable('distexe', 'distexe.c')
subproject('vcssub', required : false) test('dist test', e)
subproject('tarballsub', required : false) subproject('vcssub', required : false)
''') subproject('tarballsub', required : false)
'''))
with open(os.path.join(project_dir, 'distexe.c'), 'w') as ofile: with open(os.path.join(project_dir, 'distexe.c'), 'w') as ofile:
ofile.write('''#include<stdio.h> ofile.write(textwrap.dedent('''\
#include<stdio.h>
int main(int argc, char **argv) { int main(int argc, char **argv) {
printf("I am a distribution test.\\n"); printf("I am a distribution test.\\n");
return 0; return 0;
} }
''') '''))
xz_distfile = os.path.join(self.distdir, 'disttest-1.4.3.tar.xz') xz_distfile = os.path.join(self.distdir, 'disttest-1.4.3.tar.xz')
xz_checksumfile = xz_distfile + '.sha256sum' xz_checksumfile = xz_distfile + '.sha256sum'
zip_distfile = os.path.join(self.distdir, 'disttest-1.4.3.zip') zip_distfile = os.path.join(self.distdir, 'disttest-1.4.3.zip')
@ -3615,8 +3617,8 @@ int main(int argc, char **argv) {
""" """
tdir = os.path.join(self.unit_test_dir, '30 shared_mod linking') tdir = os.path.join(self.unit_test_dir, '30 shared_mod linking')
out = self.init(tdir) out = self.init(tdir)
msg = ('''WARNING: target links against shared modules. This is not msg = ('WARNING: target links against shared modules. This is not '
recommended as it is not supported on some platforms''') 'recommended as it is not supported on some platforms')
self.assertIn(msg, out) self.assertIn(msg, out)
def test_ndebug_if_release_disabled(self): def test_ndebug_if_release_disabled(self):
@ -7265,16 +7267,18 @@ class LinuxlikeTests(BasePlatformTests):
testdir = os.path.join(self.unit_test_dir, '61 identity cross') testdir = os.path.join(self.unit_test_dir, '61 identity cross')
nativefile = tempfile.NamedTemporaryFile(mode='w') nativefile = tempfile.NamedTemporaryFile(mode='w')
nativefile.write('''[binaries] nativefile.write(textwrap.dedent('''\
c = ['{0}'] [binaries]
'''.format(os.path.join(testdir, 'build_wrapper.py'))) c = ['{0}']
'''.format(os.path.join(testdir, 'build_wrapper.py'))))
nativefile.flush() nativefile.flush()
self.meson_native_file = nativefile.name self.meson_native_file = nativefile.name
crossfile = tempfile.NamedTemporaryFile(mode='w') crossfile = tempfile.NamedTemporaryFile(mode='w')
crossfile.write('''[binaries] crossfile.write(textwrap.dedent('''\
c = ['{0}'] [binaries]
'''.format(os.path.join(testdir, 'host_wrapper.py'))) c = ['{0}']
'''.format(os.path.join(testdir, 'host_wrapper.py'))))
crossfile.flush() crossfile.flush()
self.meson_cross_file = crossfile.name self.meson_cross_file = crossfile.name
@ -7287,9 +7291,10 @@ c = ['{0}']
'CC_FOR_BUILD': '"' + os.path.join(testdir, 'build_wrapper.py') + '"', 'CC_FOR_BUILD': '"' + os.path.join(testdir, 'build_wrapper.py') + '"',
} }
crossfile = tempfile.NamedTemporaryFile(mode='w') crossfile = tempfile.NamedTemporaryFile(mode='w')
crossfile.write('''[binaries] crossfile.write(textwrap.dedent('''\
c = ['{0}'] [binaries]
'''.format(os.path.join(testdir, 'host_wrapper.py'))) c = ['{0}']
'''.format(os.path.join(testdir, 'host_wrapper.py'))))
crossfile.flush() crossfile.flush()
self.meson_cross_file = crossfile.name self.meson_cross_file = crossfile.name
# TODO should someday be explicit about build platform only here # TODO should someday be explicit about build platform only here

@ -1,7 +1,7 @@
{ {
"stdout": [ "stdout": [
{ {
"line": "test cases/failing/76 link with shared module on osx/meson.build:8:0: ERROR: target links against shared modules." "line": "test cases/failing/76 link with shared module on osx/meson.build:8:0: ERROR: target links against shared modules. This is not permitted on OSX"
} }
] ]
} }

Loading…
Cancel
Save