diff options
author | Evan Jones <ej@evanjones.ca> | 2012-01-04 19:58:42 (GMT) |
---|---|---|
committer | Evan Jones <ej@evanjones.ca> | 2012-01-04 22:36:08 (GMT) |
commit | 16e4419e88925b82c1158fcfbbb78c2e30f91905 (patch) | |
tree | dec8e6fcfe6e98e1541697e32b1c8b8b486f8acf | |
parent | b12139c13e8924ce4d0e634f5798274a5d87f5d7 (diff) | |
download | Ninja-16e4419e88925b82c1158fcfbbb78c2e30f91905.zip Ninja-16e4419e88925b82c1158fcfbbb78c2e30f91905.tar.gz Ninja-16e4419e88925b82c1158fcfbbb78c2e30f91905.tar.bz2 |
ninja_syntax.py: Fix a bug when passing dict variables to Writer.build()
Add a test to cover both dict and list variables.
-rw-r--r-- | misc/ninja_syntax.py | 7 | ||||
-rwxr-xr-x | misc/ninja_test.py | 21 |
2 files changed, 27 insertions, 1 deletions
diff --git a/misc/ninja_syntax.py b/misc/ninja_syntax.py index b73a002..2e487d1 100644 --- a/misc/ninja_syntax.py +++ b/misc/ninja_syntax.py @@ -66,7 +66,12 @@ class Writer(object): ' '.join(all_inputs))) if variables: - for key, val in variables: + if isinstance(variables, dict): + iterator = variables.iteritems() + else: + iterator = iter(variables) + + for key, val in iterator: self.variable(key, val, indent=1) return outputs diff --git a/misc/ninja_test.py b/misc/ninja_test.py index 65dbec6..897de72 100755 --- a/misc/ninja_test.py +++ b/misc/ninja_test.py @@ -111,5 +111,26 @@ foo = a$$ $ ''', self.out.getvalue()) +class TestBuild(unittest.TestCase): + def setUp(self): + self.out = StringIO() + self.n = ninja_syntax.Writer(self.out) + + def test_variables_dict(self): + self.n.build('out', 'cc', 'in', variables={'name': 'value'}) + self.assertEqual('''\ +build out: cc in + name = value +''', + self.out.getvalue()) + + def test_variables_list(self): + self.n.build('out', 'cc', 'in', variables=[('name', 'value')]) + self.assertEqual('''\ +build out: cc in + name = value +''', + self.out.getvalue()) + if __name__ == '__main__': unittest.main() |