summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2014-08-05 17:52:15 +0800
committerChun-wei Fan <fanchunwei@src.gnome.org>2015-07-22 16:12:11 +0800
commitf5521bc0ada45028ee7053ec38dd61db169c88a0 (patch)
tree925f741d25d5e09793ca1dd8945158f1b9aefe37
parent0c22de3cbaed509851c5e69653ebda5f85a45b77 (diff)
downloadgobject-introspection-wip/fanc999/dumper-distutils.tar.gz
tests/scanner: Add a test for ccompiler.pywip/fanc999/dumper-distutils
This adds a test for ccompiler.py so that we can test the compiler instance creation via ccompiler.py (and therefore distutils), so that we can get the correct compiler instances as we ask for them. https://bugzilla.gnome.org/show_bug.cgi?id=728313
-rw-r--r--tests/scanner/Makefile.am1
-rw-r--r--tests/scanner/test_ccompiler.py80
2 files changed, 81 insertions, 0 deletions
diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am
index 13156c3b..2c016992 100644
--- a/tests/scanner/Makefile.am
+++ b/tests/scanner/Makefile.am
@@ -229,6 +229,7 @@ CHECKDOCS =
endif
PYTESTS = \
+ test_ccompiler.py \
test_sourcescanner.py \
test_transformer.py
diff --git a/tests/scanner/test_ccompiler.py b/tests/scanner/test_ccompiler.py
new file mode 100644
index 00000000..9e7a62a2
--- /dev/null
+++ b/tests/scanner/test_ccompiler.py
@@ -0,0 +1,80 @@
+import unittest
+import os
+import sys
+
+from distutils.cygwinccompiler import Mingw32CCompiler
+from distutils.unixccompiler import UnixCCompiler
+from distutils.msvccompiler import MSVCCompiler
+
+os.environ['GI_SCANNER_DISABLE_CACHE'] = '1'
+path = os.getenv('UNINSTALLED_INTROSPECTION_SRCDIR', None)
+assert path is not None
+sys.path.insert(0, path)
+
+from giscanner.ccompiler import CCompiler
+
+
+class TestCompiler(unittest.TestCase):
+
+ def check_windows_default_compiler(self, compiler):
+ if os.environ.get('MSYSTEM') == 'MINGW32':
+ return isinstance(compiler.compiler, Mingw32CCompiler)
+ else:
+ return isinstance(compiler.compiler, MSVCCompiler)
+
+ def check_default_compiler(self, compiler, osname=None):
+ # If osname is defined and is not 'nt', we always return the default
+ # compiler given for the running platform. Otherwise, on Windows,
+ # we see for the presence of MSYSTEM == MINGW32 to see we create a
+ # Mingw32CCompiler or MSVCCompiler instance
+ if os.name == 'nt':
+ if osname is None or osname == os.name:
+ return self.check_windows_default_compiler(compiler)
+ else:
+ return isinstance(compiler.compiler, MSVCCompiler)
+ else:
+ return (isinstance(compiler.compiler, UnixCCompiler) and
+ not isinstance(compiler.compiler, Mingw32CCompiler))
+
+ def test_compiler_creation(self):
+ osname = 'nt'
+ # Test distutils compiler detection when forcing osname = 'nt'
+ compiler = CCompiler(osname=osname, environ={'MSYSTEM': 'MINGW32'})
+ self.assertTrue(isinstance(compiler.compiler, Mingw32CCompiler))
+
+ compiler = CCompiler(osname=osname, compiler_name='mingw32')
+ self.assertTrue(isinstance(compiler.compiler, Mingw32CCompiler))
+
+ compiler = CCompiler(osname=osname, compiler_name='msvc')
+ self.assertTrue(isinstance(compiler.compiler, MSVCCompiler))
+
+ with self.assertRaises(SystemExit):
+ CCompiler(osname=osname, compiler_name='bad_compiler_name')
+
+ if os.name == 'nt':
+ compiler = CCompiler(osname=osname)
+ self.assertTrue(self.check_windows_default_compiler(compiler))
+ else:
+ with self.assertRaises(SystemExit):
+ CCompiler(osname=osname, compiler_name='bad_compiler_name')
+
+ # Test distutils compiler detection when forcing osname != 'nt'
+ osname = 'posix'
+ compiler = CCompiler(osname=osname, environ={'MSYSTEM': 'MINGW32'})
+ self.assertTrue(self.check_default_compiler(compiler, osname))
+
+ compiler = CCompiler(osname=osname, compiler_name='mingw32')
+ self.assertTrue(self.check_default_compiler(compiler, osname))
+
+ compiler = CCompiler(osname=osname, compiler_name='msvc')
+ self.assertTrue(self.check_default_compiler(compiler, osname))
+
+ compiler = CCompiler(osname=osname, compiler_name='blah')
+ self.assertTrue(self.check_default_compiler(compiler, osname))
+
+ # Test default distutils compiler with ccompiler.py
+ compiler = CCompiler()
+ self.assertTrue(self.check_default_compiler(compiler))
+
+if __name__ == '__main__':
+ unittest.main()