summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2018-07-25 12:24:50 +0200
committerChristoph Reiter <reiter.christoph@gmail.com>2018-07-25 17:04:22 +0200
commitc26a7548f43d7fad96c4c7d83aeb7150bcb9e48b (patch)
tree4399719faa5279fb8a5ff484ed623f4f36cb63ff /tests
parent96df6e243642ee8fe435f6d4108295d20d659b20 (diff)
downloadgobject-introspection-c26a7548f43d7fad96c4c7d83aeb7150bcb9e48b.tar.gz
transformer: don't shell out for filter commands and make the tests work on Windows
Instead of passing the filter commands to the shell, split them with the shlex module. This gives us more control and a more similar behaviour on unix/win32 systems. I could only find two users in Debian which just call python with some script, so this seems safe to me. Adjust the tests accordingly and use the running python executable to test the functionality as we can be sure that's available on all platforms. Also add a new test for the symbol filter commadn which wasn't tested before.
Diffstat (limited to 'tests')
-rw-r--r--tests/scanner/meson.build11
-rw-r--r--tests/scanner/test_transformer.py38
2 files changed, 29 insertions, 20 deletions
diff --git a/tests/scanner/meson.build b/tests/scanner/meson.build
index 86c7d5da..07df91a9 100644
--- a/tests/scanner/meson.build
+++ b/tests/scanner/meson.build
@@ -6,17 +6,14 @@ scanner_test_files = [
'test_shlibs.py',
]
-# FIXME: Windows
-if host_system != 'windows'
- scanner_test_files += ['test_transformer.py']
-endif
-
# FIXME: MSVC
if cc.get_id() != 'msvc'
- scanner_test_files += ['test_sourcescanner.py']
+ scanner_test_files += [
+ 'test_sourcescanner.py',
+ 'test_transformer.py',
+ ]
endif
foreach f : scanner_test_files
test(f, python, args: files(f), env: scanner_test_env)
endforeach
-
diff --git a/tests/scanner/test_transformer.py b/tests/scanner/test_transformer.py
index 13b0b669..467f0c5c 100644
--- a/tests/scanner/test_transformer.py
+++ b/tests/scanner/test_transformer.py
@@ -42,16 +42,15 @@ def load_namespace_from_source_string(namespace, source):
class TestIdentifierFilter(unittest.TestCase):
def test_underscore_t_identifier_filter(self):
- cmd = textwrap.dedent(r"""
- python -c '
- import sys, re
- for line in sys.stdin:
- line = re.sub(r"^test_t$", "TestContext", line)
- line = re.sub(r"_t$", "", line)
- line = re.sub(r"^test_", "Test_", line)
- line = re.sub(r"_([a-z])", lambda m: m.group(1).title(),
- line)
- sys.stdout.write(line)'""")
+ cmd = [sys.executable, '-c', textwrap.dedent("""
+ import sys, re
+ for line in sys.stdin:
+ line = re.sub(r"^test_t$", "TestContext", line)
+ line = re.sub(r"_t$", "", line)
+ line = re.sub(r"^test_", "Test_", line)
+ line = re.sub(r"_([a-z])", lambda m: m.group(1).title(),
+ line)
+ sys.stdout.write(line)""")]
namespace = ast.Namespace('Test', '1.0')
xformer = Transformer(namespace, identifier_filter_cmd=cmd)
@@ -63,18 +62,31 @@ class TestIdentifierFilter(unittest.TestCase):
self.assertEqual(xformer.strip_identifier('test_foo_tart'), 'FooTart')
def test_invalid_command(self):
- cmd = r'this-is-not-a-real-command'
+ cmd = ['this-is-not-a-real-command']
namespace = ast.Namespace('Test', '1.0')
xformer = Transformer(namespace, identifier_filter_cmd=cmd)
- self.assertRaises(ValueError, xformer.strip_identifier, 'test_t')
+ self.assertRaises(OSError, xformer.strip_identifier, 'test_t')
def test_invalid_argument(self):
- cmd = r'sed --not-a-valid-argument'
+ cmd = [sys.executable, '--not-a-valid-argument']
namespace = ast.Namespace('Test', '1.0')
xformer = Transformer(namespace, identifier_filter_cmd=cmd)
self.assertRaises(ValueError, xformer.strip_identifier, 'test_t')
+class TestSymbolFilter(unittest.TestCase):
+
+ def test_split_csymbol(self):
+ cmd = [
+ sys.executable, '-c',
+ 'import sys; sys.stdout.write("test_" + sys.stdin.read())']
+ namespace = ast.Namespace('Test', '1.0')
+ xformer = Transformer(namespace, symbol_filter_cmd=cmd)
+
+ self.assertEqual(
+ xformer.split_csymbol('foo_bar_quux')[1], "foo_bar_quux")
+
+
class TestStructTypedefs(unittest.TestCase):
def setUp(self):
# Hack to set logging singleton