summaryrefslogtreecommitdiffstats
path: root/xpcom/idl-parser/xpidl/runtests.py
diff options
context:
space:
mode:
Diffstat (limited to 'xpcom/idl-parser/xpidl/runtests.py')
-rwxr-xr-xxpcom/idl-parser/xpidl/runtests.py41
1 files changed, 40 insertions, 1 deletions
diff --git a/xpcom/idl-parser/xpidl/runtests.py b/xpcom/idl-parser/xpidl/runtests.py
index 2dd269dfd9..b889d40010 100755
--- a/xpcom/idl-parser/xpidl/runtests.py
+++ b/xpcom/idl-parser/xpidl/runtests.py
@@ -5,6 +5,8 @@
#
# Unit tests for xpidl.py
+import json
+import os
import sys
# Hack: the first entry in sys.path is the directory containing the script.
@@ -16,7 +18,7 @@ import unittest
import mozunit
-from xpidl import header, xpidl
+from xpidl import header, typescript, xpidl
class TestParser(unittest.TestCase):
@@ -253,5 +255,42 @@ attribute long bar;
self.assertEqual(e.args[0], ("cannot find symbol 'Y'"))
+class TestTypescript(unittest.TestCase):
+ """A few basic smoke tests for typescript generation."""
+
+ dir = os.path.dirname(__file__)
+ src = os.path.join(dir, "..", "..", "..")
+
+ # We use the xpctest.xpt *.idl files from:
+ tests_dir = os.path.join(src, "js/xpconnect/tests/idl")
+ files = [
+ "xpctest_attributes.idl",
+ "xpctest_bug809674.idl",
+ "xpctest_cenums.idl",
+ "xpctest_interfaces.idl",
+ "xpctest_params.idl",
+ "xpctest_returncode.idl",
+ "xpctest_utils.idl",
+ ]
+
+ fixtures = os.path.join(dir, "fixtures")
+ inc_dirs = [os.path.join(src, "xpcom/base")]
+
+ def setUp(self):
+ self.parser = xpidl.IDLParser()
+
+ def test_d_json(self):
+ mods = []
+ for file in self.files:
+ path = os.path.join(self.tests_dir, file)
+ idl = self.parser.parse(open(path).read(), path)
+ idl.resolve(self.inc_dirs, self.parser, {})
+ mods.append(typescript.ts_source(idl))
+
+ result = json.dumps(mods, indent=2, sort_keys=True)
+ expected = open(os.path.join(self.fixtures, "xpctest.d.json")).read()
+ self.assertEqual(result, expected, "types data json does not match")
+
+
if __name__ == "__main__":
mozunit.main(runwith="unittest")