Esempio n. 1
0
    def test_rule_stmt(self):
        input_path = os.path.join(TEST_DATA_DIR, 'rule.ninja')

        parser = ninja.Parser()
        manifest = parser.parse(input_path, ENCODING)

        self.assertEqual(2, len(manifest.rules))

        rule_cc = manifest.rules[0]
        self.assertEqual('cc', rule_cc.name)
        self.assertEqual(1, len(rule_cc.bindings))

        sb = ninja.EvalStringBuilder()
        sb.append_raw('gcc -c -o ')
        sb.append_var('outs')
        sb.append_raw(' ')
        sb.append_var('ins')

        self.assertEqual(sb.getvalue(), rule_cc.bindings['command'])

        rule_ld = manifest.rules[1]
        self.assertEqual('ld', rule_ld.name)
        self.assertEqual(1, len(rule_ld.bindings))

        sb = ninja.EvalStringBuilder()
        sb.append_raw('gcc -o ')
        sb.append_var('outs')
        sb.append_raw(' ')
        sb.append_var('ins')

        self.assertEqual(sb.getvalue(), rule_ld.bindings['command'])
Esempio n. 2
0
    def test_circular_eval_eval_error(self):
        env = ninja.EvalEnv()
        env['a'] = ninja.EvalStringBuilder().append_var('b').getvalue()
        env['b'] = ninja.EvalStringBuilder().append_var('b').getvalue()

        s = ninja.EvalStringBuilder().append_var('a').getvalue()
        with self.assertRaises(ninja.EvalCircularError):
            ninja.eval_string(s, env)
Esempio n. 3
0
    def test_var_concat_eval(self):
        env = ninja.EvalEnv()
        env['key1'] = ninja.EvalStringBuilder().append_raw('a').getvalue()
        env['key2'] = ninja.EvalStringBuilder().append_raw('b').getvalue()

        sb = ninja.EvalStringBuilder()
        sb.append_var('key1')
        sb.append_var('key2')
        s = sb.getvalue()

        self.assertEqual('ab', ninja.eval_string(s, env))
Esempio n. 4
0
    def test_raw_and_var_eval(self):
        env = ninja.EvalEnv()
        env['b'] = ninja.EvalStringBuilder().append_raw('d').getvalue()

        sb = ninja.EvalStringBuilder()
        sb.append_raw('a')
        sb.append_var('b')
        sb.append_raw('c')
        s = sb.getvalue()

        self.assertEqual('adc', ninja.eval_string(s, env))
Esempio n. 5
0
    def test_append_raw_concat(self):
        sb = ninja.EvalStringBuilder()
        sb.append_raw('a')
        sb.append_raw('b')
        s = sb.getvalue()

        self.assertTrue(s)
        self.assertEqual('ab', ninja.eval_string(s, ninja.EvalEnv()))
Esempio n. 6
0
 def test_unknown_variable_eval_error(self):
     s = ninja.EvalStringBuilder().append_var('a').getvalue()
     self.assertEqual('', ninja.eval_string(s, ninja.EvalEnv()))
Esempio n. 7
0
    def test_var_eval(self):
        env = ninja.EvalEnv()
        env['key'] = ninja.EvalStringBuilder().append_raw('value').getvalue()

        s = ninja.EvalStringBuilder().append_var('key').getvalue()
        self.assertEqual('value', ninja.eval_string(s, env))
Esempio n. 8
0
 def test_append_var(self):
     s = ninja.EvalStringBuilder().append_var('key').getvalue()
     self.assertTrue(s)
Esempio n. 9
0
 def test_append_raw(self):
     s = ninja.EvalStringBuilder().append_raw('a').getvalue()
     self.assertTrue(s)
     self.assertEqual('a', ninja.eval_string(s, ninja.EvalEnv()))
Esempio n. 10
0
 def test_empty(self):
     s = ninja.EvalStringBuilder().getvalue()
     self.assertFalse(s)
     self.assertEqual('', ninja.eval_string(s, ninja.EvalEnv()))