summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Reiter <reiter.christoph@gmail.com>2019-01-08 13:54:33 +0100
committerChristoph Reiter <reiter.christoph@gmail.com>2019-01-08 13:55:53 +0100
commit781711c33c4252802d74908a03b0135f8c7cc17b (patch)
tree752701a0b672eb31c47835d2ebe02dcb701ebca0
parent362c656c3152295afd144f3ed551d1eb4ab57445 (diff)
downloadgobject-introspection-781711c33c4252802d74908a03b0135f8c7cc17b.tar.gz
tests: add some tests for get_source_root_dirs
To make it easier to test make sure it always returns absolute paths. Also fix a typo, oops!
-rw-r--r--giscanner/scannermain.py4
-rw-r--r--tests/scanner/Makefile.am3
-rw-r--r--tests/scanner/meson.build1
-rw-r--r--tests/scanner/test_scanner.py30
4 files changed, 35 insertions, 3 deletions
diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py
index b6bbe9d7..df721212 100644
--- a/giscanner/scannermain.py
+++ b/giscanner/scannermain.py
@@ -493,10 +493,10 @@ def write_output(data, options):
def get_source_root_dirs(options, filenames):
if options.sources_top_dirs:
- return options.sources_top_dir
+ return [os.path.realpath(p) for p in options.sources_top_dirs]
# None passed, we need to guess
- assert all(os.path.isabs(f) for f in filenames)
+ filenames = [os.path.realpath(p) for p in filenames]
dirs = sorted(set([os.path.dirname(f) for f in filenames]))
# We need commonpath (3.5+), otherwise give up
diff --git a/tests/scanner/Makefile.am b/tests/scanner/Makefile.am
index 9e424d76..734f30e8 100644
--- a/tests/scanner/Makefile.am
+++ b/tests/scanner/Makefile.am
@@ -235,7 +235,8 @@ PYTESTS = \
test_sourcescanner.py \
test_transformer.py \
test_xmlwriter.py \
- test_docwriter.py
+ test_docwriter.py \
+ test_scanner.py
TESTS = $(CHECKGIRS) $(CHECKDOCS) $(TYPELIBS) $(PYTESTS)
TESTS_ENVIRONMENT = env srcdir=$(srcdir) top_srcdir=$(top_srcdir) builddir=$(builddir) top_builddir=$(top_builddir) \
diff --git a/tests/scanner/meson.build b/tests/scanner/meson.build
index ab5da15a..95a9dacc 100644
--- a/tests/scanner/meson.build
+++ b/tests/scanner/meson.build
@@ -12,6 +12,7 @@ scanner_test_files = [
'test_xmlwriter.py',
'test_pkgconfig.py',
'test_docwriter.py',
+ 'test_scanner.py',
]
foreach f : scanner_test_files
diff --git a/tests/scanner/test_scanner.py b/tests/scanner/test_scanner.py
new file mode 100644
index 00000000..2513c0de
--- /dev/null
+++ b/tests/scanner/test_scanner.py
@@ -0,0 +1,30 @@
+import unittest
+import optparse
+import os
+
+from giscanner.scannermain import get_source_root_dirs
+
+
+class TestScanner(unittest.TestCase):
+
+ def test_get_source_root_dirs_options(self):
+ options = optparse.Values({"sources_top_dirs": ["foo"]})
+ paths = get_source_root_dirs(options, ["nope"])
+ self.assertEqual(len(paths), 1)
+ self.assertTrue(os.path.isabs(paths[0]))
+ self.assertEqual(paths[0], os.path.join(os.getcwd(), "foo"))
+
+ def test_get_source_root_dirs_guess(self):
+ options = optparse.Values({"sources_top_dirs": []})
+ cwd = os.getcwd()
+ paths = get_source_root_dirs(
+ options, [os.path.join(cwd, "foo"), os.path.join(cwd, "bar")])
+ self.assertEqual(len(paths), 1)
+ self.assertEqual(paths[0], cwd)
+
+ paths = get_source_root_dirs(options, [])
+ self.assertEqual(paths, [])
+
+
+if __name__ == '__main__':
+ unittest.main()