summaryrefslogtreecommitdiff
path: root/tools/setup_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/setup_test.py')
-rw-r--r--tools/setup_test.py104
1 files changed, 54 insertions, 50 deletions
diff --git a/tools/setup_test.py b/tools/setup_test.py
index 63ddfb413..5434b42ab 100644
--- a/tools/setup_test.py
+++ b/tools/setup_test.py
@@ -1,67 +1,71 @@
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import os
+import sys
+import unittest
+
from setup import gn_string, read_gn_args, write_gn_args
from shutil import rmtree
from tempfile import mktemp
-def gn_string_test():
- assert '"abc"' == gn_string('abc')
- assert '"foo\\$bar\\"baz"' == gn_string('foo$bar"baz')
- assert '"do\\not\\escape"' == gn_string('do\\not\\escape')
- assert '"so\\\\\\very\\\\\\"fun\\"' == gn_string('so\\\\very\\"fun\\')
-
-
-def read_gn_args_test():
- # Args file doesn't exist.
- (args, hand_edited) = read_gn_args("/baddir/hopefully/nonexistent/args.gn")
- assert args is None
- assert hand_edited == False
+class TestSetup(unittest.TestCase):
+ def test_gn_string(self):
+ assert '"abc"' == gn_string('abc')
+ assert '"foo\\$bar\\"baz"' == gn_string('foo$bar"baz')
+ assert '"do\\not\\escape"' == gn_string('do\\not\\escape')
+ assert '"so\\\\\\very\\\\\\"fun\\"' == gn_string('so\\\\very\\"fun\\')
- # Handwritten empty args file.
- filename = mktemp()
- with open(filename, "w"):
- pass
- (args, hand_edited) = read_gn_args(filename)
- os.remove(filename)
- assert args == []
- assert hand_edited == True
+ def test_read_gn_args(self):
+ # Args file doesn't exist.
+ (args,
+ hand_edited) = read_gn_args("/baddir/hopefully/nonexistent/args.gn")
+ assert args is None
+ assert hand_edited == False
- # Handwritten non-empty args file.
- expect_args = ['some_number=2', 'another_string="ran/dom#yes"']
- filename = mktemp()
- with open(filename, "w") as f:
- f.write("\n".join(expect_args + ["", "# A comment to be ignored"]))
- (args, hand_edited) = read_gn_args(filename)
- os.remove(filename)
- assert args == expect_args
- assert hand_edited == True
+ # Handwritten empty args file.
+ filename = mktemp()
+ with open(filename, "w"):
+ pass
+ (args, hand_edited) = read_gn_args(filename)
+ os.remove(filename)
+ assert args == []
+ assert hand_edited == True
+ # Handwritten non-empty args file.
+ expect_args = ['some_number=2', 'another_string="ran/dom#yes"']
+ filename = mktemp()
+ with open(filename, "w") as f:
+ f.write("\n".join(expect_args + ["", "# A comment to be ignored"]))
+ (args, hand_edited) = read_gn_args(filename)
+ os.remove(filename)
+ assert args == expect_args
+ assert hand_edited == True
-def write_gn_args_test():
- # Build a nonexistent path; write_gn_args() should call mkdir as needed.
- d = mktemp()
- filename = os.path.join(d, "args.gn")
- assert not os.path.exists(d)
- assert not os.path.exists(filename)
- # Write some args.
- args = ['lalala=42', 'foo_bar_baz="lorem ipsum dolor#amet"']
- write_gn_args(filename, args)
- # Directory and args file should now be created.
- assert os.path.isdir(d)
- assert os.path.isfile(filename)
- # Validate that the right contents were written.
- (check_args, hand_edited) = read_gn_args(filename)
- assert check_args == args
- assert hand_edited == False
- # Clean up.
- rmtree(d)
+ def test_write_gn_args(self):
+ # Build a nonexistent path; write_gn_args() should call mkdir as needed.
+ d = mktemp()
+ filename = os.path.join(d, "args.gn")
+ assert not os.path.exists(d)
+ assert not os.path.exists(filename)
+ # Write some args.
+ args = ['lalala=42', 'foo_bar_baz="lorem ipsum dolor#amet"']
+ write_gn_args(filename, args)
+ # Directory and args file should now be created.
+ assert os.path.isdir(d)
+ assert os.path.isfile(filename)
+ # Validate that the right contents were written.
+ (check_args, hand_edited) = read_gn_args(filename)
+ assert check_args == args
+ assert hand_edited == False
+ # Clean up.
+ rmtree(d)
def setup_test():
- gn_string_test()
- read_gn_args_test()
- write_gn_args_test()
+ suite = unittest.TestLoader().loadTestsFromTestCase(TestSetup)
+ result = unittest.TextTestRunner(verbosity=2).run(suite)
+ if not result.wasSuccessful():
+ sys.exit(1)
if __name__ == '__main__':