[glib/fix-mkenums-genmarshal-test-windows] GObject: Fix mkenums.py and genmarshal.py tests on Windows
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/fix-mkenums-genmarshal-test-windows] GObject: Fix mkenums.py and genmarshal.py tests on Windows
- Date: Mon, 24 Jun 2019 10:44:19 +0000 (UTC)
commit 4c5d69d61881db915889cdf1a2e42c888cf3f4ca
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Jun 24 18:33:39 2019 +0800
GObject: Fix mkenums.py and genmarshal.py tests on Windows
The two test scripts actually assumed some *NIX paradigms, so we need
to adapt them so that they can work on Windows as well, the changes are
namely:
-Call the glib-mkenums and glib-genmarshal Python scripts with the
Python interpreter, not just relying on shebang lines, on Windows.
This is because the native Windows console (cmd.exe) does not support
shebang lines.
-Use NamedTemporaryFile with delete=False, otherwise Windows cannot find
the temp files we need when running the tests.
-We are using stdout, so we need to account for line ending differences,
i.e. '\r\n' vs '\n'.
-Make sure we are not in the temp directories we create, where the tests
are being run, upon cleanup. Windows does not like deleting
directories that we are currently in.
gobject/tests/genmarshal.py | 21 ++++++++++++++++++---
gobject/tests/mkenums.py | 29 ++++++++++++++++++++++-------
2 files changed, 40 insertions(+), 10 deletions(-)
---
diff --git a/gobject/tests/genmarshal.py b/gobject/tests/genmarshal.py
index 0da61f3a2..5fbca921c 100644
--- a/gobject/tests/genmarshal.py
+++ b/gobject/tests/genmarshal.py
@@ -22,6 +22,7 @@
import collections
import os
+import sys
import shutil
import subprocess
import tempfile
@@ -46,9 +47,13 @@ class TestGenmarshal(unittest.TestCase):
parsing and generation code out into a library and unit test that, and
convert this test to just check command line behaviour.
"""
+ # Track the cwd, we want to back out to that to clean up our tempdir
+ cwd = ''
+
def setUp(self):
self.timeout_seconds = 10 # seconds per test
self.tmpdir = tempfile.TemporaryDirectory()
+ self.cwd = os.getcwd()
os.chdir(self.tmpdir.name)
print('tmpdir:', self.tmpdir.name)
if 'G_TEST_BUILDDIR' in os.environ:
@@ -60,10 +65,17 @@ class TestGenmarshal(unittest.TestCase):
print('genmarshal:', self.__genmarshal)
def tearDown(self):
+ os.chdir(self.cwd)
self.tmpdir.cleanup()
def runGenmarshal(self, *args):
argv = [self.__genmarshal]
+
+ # shebang lines are not supported on native
+ # Windows consoles
+ if os.name == 'nt':
+ argv.insert(0, sys.executable)
+
argv.extend(args)
print('Running:', argv)
@@ -76,8 +88,10 @@ class TestGenmarshal(unittest.TestCase):
stderr=subprocess.PIPE,
env=env)
info.check_returncode()
- out = info.stdout.decode('utf-8').strip()
- err = info.stderr.decode('utf-8').strip()
+
+ # We want to ensure consistent line endings...
+ out = info.stdout.decode('utf-8').strip().replace('\r\n', '\n')
+ err = info.stderr.decode('utf-8').strip().replace('\r\n', '\n')
# Known substitutions for standard boilerplate
subs = {
@@ -156,7 +170,8 @@ class TestGenmarshal(unittest.TestCase):
def runGenmarshalWithList(self, list_contents, *args):
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
- suffix='.list') as list_file:
+ suffix='.list',
+ delete=False) as list_file:
# Write out the list.
list_file.write(list_contents.encode('utf-8'))
print(list_file.name + ':', list_contents)
diff --git a/gobject/tests/mkenums.py b/gobject/tests/mkenums.py
index 9b4632497..638aa1749 100644
--- a/gobject/tests/mkenums.py
+++ b/gobject/tests/mkenums.py
@@ -22,6 +22,7 @@
import collections
import os
+import sys
import shutil
import subprocess
import tempfile
@@ -46,11 +47,14 @@ class TestMkenums(unittest.TestCase):
parsing and generation code out into a library and unit test that, and
convert this test to just check command line behaviour.
"""
+ # Track the cwd, we want to back out to that to clean up our tempdir
+ cwd = ''
rspfile = False
def setUp(self):
self.timeout_seconds = 10 # seconds per test
self.tmpdir = tempfile.TemporaryDirectory()
+ self.cwd = os.getcwd()
os.chdir(self.tmpdir.name)
print('tmpdir:', self.tmpdir.name)
if 'G_TEST_BUILDDIR' in os.environ:
@@ -62,6 +66,7 @@ class TestMkenums(unittest.TestCase):
print('rspfile: {}, mkenums:'.format(self.rspfile), self.__mkenums)
def tearDown(self):
+ os.chdir(self.cwd)
self.tmpdir.cleanup()
def _write_rspfile(self, argv):
@@ -72,13 +77,19 @@ class TestMkenums(unittest.TestCase):
print('Response file contains:', contents)
f.write(contents)
f.flush()
- return f.name
+ return f.name
def runMkenums(self, *args):
if self.rspfile:
rspfile = self._write_rspfile(args)
args = ['@' + rspfile]
argv = [self.__mkenums]
+
+ # shebang lines are not supported on native
+ # Windows consoles
+ if os.name == 'nt':
+ argv.insert(0, sys.executable)
+
argv.extend(args)
print('Running:', argv)
@@ -91,8 +102,10 @@ class TestMkenums(unittest.TestCase):
stderr=subprocess.PIPE,
env=env)
info.check_returncode()
- out = info.stdout.decode('utf-8').strip()
- err = info.stderr.decode('utf-8').strip()
+
+ # We want to ensure consistent line endings...
+ out = info.stdout.decode('utf-8').strip().replace('\r\n', '\n')
+ err = info.stderr.decode('utf-8').strip().replace('\r\n', '\n')
# Known substitutions for standard boilerplate
subs = {
@@ -111,7 +124,8 @@ class TestMkenums(unittest.TestCase):
def runMkenumsWithTemplate(self, template_contents, *args):
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
- suffix='.template') as template_file:
+ suffix='.template',
+ delete=False) as template_file:
# Write out the template.
template_file.write(template_contents.encode('utf-8'))
print(template_file.name + ':', template_contents)
@@ -191,7 +205,8 @@ file-tail
def runMkenumsWithHeader(self, h_contents, encoding='utf-8'):
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
- suffix='.h') as h_file:
+ suffix='.h',
+ delete=False) as h_file:
# Write out the header to be scanned.
h_file.write(h_contents.encode(encoding))
print(h_file.name + ':', h_contents)
@@ -381,9 +396,9 @@ comment: {standard_bottom_comment}
'''
with tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
- suffix='1.h') as h_file1, \
+ suffix='1.h', delete=False) as h_file1, \
tempfile.NamedTemporaryFile(dir=self.tmpdir.name,
- suffix='2.h') as h_file2:
+ suffix='2.h', delete=False) as h_file2:
# Write out the headers.
h_file1.write(h_contents1.encode('utf-8'))
h_file2.write(h_contents2.encode('utf-8'))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]