示例#1
0
    def setUp(self):
        self.rdb = RuleCloth()
        self.rule_name = 'ccompile'
        self.example_rule = {
            'name': self.rule_name,
            'description': 'compile $file',
            'command': ['cc $in']
        }

        self.rule_obj = Rule(self.rule_name)
        self.rule_obj._rule = self.example_rule
示例#2
0
    def setUp(self):
        self.rdb = RuleCloth()
        self.rule_name = 'ccompile'
        self.example_rule = { 'name': self.rule_name, 'description': 'compile $file', 'command': ['cc $in'] }

        self.rule_obj = Rule(self.rule_name)
        self.rule_obj._rule = self.example_rule
示例#3
0
class TestBuildRules(TestCase):
    @classmethod
    def setUp(self):
        self.rdb = RuleCloth()
        self.rule_name = 'ccompile'
        self.example_rule = { 'name': self.rule_name, 'description': 'compile $file', 'command': ['cc $in'] }

        self.rule_obj = Rule(self.rule_name)
        self.rule_obj._rule = self.example_rule

    def test_add_rule_in_list(self):
        self.rdb.add(self.rule_obj)
        self.assertTrue('ccompile' in self.rdb.list_rules())
    
    def test_add_rule_without_name(self):
        rule = self.rule_obj
        del rule._rule['name'] 

        with self.assertRaises(InvalidRule):
            self.rdb.add(rule)
            
    def test_add_rule_with_same_name(self):
        self.rdb.add(self.rule_obj)
        with self.assertRaises(InvalidRule):
            self.rdb.add(self.rule_obj)

    def test_add_rule_without_name(self):
        self.rdb.add(self.rule_obj)
        self.assertFalse('name' in self.rdb.rules[self.rule_name])

    def test_invalid_output_type(self):
        self.rdb.output = 'scons'
        self.rdb.add(self.rule_obj)

        with self.assertRaises(InvalidBuilder):
            self.rdb.fetch(self.rule_name)

    def test_ninja_fetch_output(self):
        self.rdb.output = 'ninja'
        self.rdb.add(self.rule_obj)
        
        ninja_rule = ['rule ccompile', '    command = cc $in', '    description = CCOMPILE compile $file']
        self.assertEqual(self.rdb.fetch(self.rule_name), ninja_rule)

    def test_make_fetch_output(self):
        self.rdb.output = 'make'

        self.rdb.add(self.rule_obj)

        make_rule = ['\t@cc $in', '\t@echo compile $file']
        self.assertEqual(self.rdb.fetch(self.rule_name), make_rule)
示例#4
0
class TestBuildRules(TestCase):
    @classmethod
    def setUp(self):
        self.rdb = RuleCloth()
        self.rule_name = 'ccompile'
        self.example_rule = {
            'name': self.rule_name,
            'description': 'compile $file',
            'command': ['cc $in']
        }

        self.rule_obj = Rule(self.rule_name)
        self.rule_obj._rule = self.example_rule

    def test_add_rule_in_list(self):
        self.rdb.add(self.rule_obj)
        self.assertTrue('ccompile' in self.rdb.list_rules())

    def test_add_rule_without_name(self):
        rule = self.rule_obj
        del rule._rule['name']

        with self.assertRaises(InvalidRule):
            self.rdb.add(rule)

    def test_add_rule_with_same_name(self):
        self.rdb.add(self.rule_obj)
        with self.assertRaises(InvalidRule):
            self.rdb.add(self.rule_obj)

    def test_add_rule_without_name(self):
        self.rdb.add(self.rule_obj)
        self.assertFalse('name' in self.rdb.rules[self.rule_name])

    def test_invalid_output_type(self):
        self.rdb.output = 'scons'
        self.rdb.add(self.rule_obj)

        with self.assertRaises(InvalidBuilder):
            self.rdb.fetch(self.rule_name)

    def test_ninja_fetch_output(self):
        self.rdb.output = 'ninja'
        self.rdb.add(self.rule_obj)

        ninja_rule = [
            'rule ccompile', '    command = cc $in',
            '    description = CCOMPILE compile $file'
        ]
        self.assertEqual(self.rdb.fetch(self.rule_name), ninja_rule)

    def test_make_fetch_output(self):
        self.rdb.output = 'make'

        self.rdb.add(self.rule_obj)

        make_rule = ['\t@cc $in', '\t@echo compile $file']
        self.assertEqual(self.rdb.fetch(self.rule_name), make_rule)