Пример #1
0
class CMakeTest(TestCase):
    def setUp(self):
        self._config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'bdemeta.json': '{"roots": ["r"]}',
            'r': {
                'standalones': {
                    'p': {
                        'package': {
                            'p.dep': '',
                            'p.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_generate_cmake(self):
        output1 = StringIO()

        run(output1, None, output1, None, ['cmake', 'bdemeta.json', 'p'])

        r       = TargetResolver(self._config)
        p       = resolve(r, 'p')
        output2 = StringIO()
        generate(p, output2)

        assert(output1.getvalue() == output2.getvalue())
Пример #2
0
class RunTest(TestCase):
    def setUp(self):
        self._config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'groups': {
                    'gr1': {
                        'group': {
                            'gr1.dep': '',
                            'gr1.mem': 'gr1p1 gr1p2',
                        },
                        'gr1p1': {
                            'package': {
                                'gr1p1.dep': '',
                                'gr1p1.mem': '',
                            },
                        },
                        'gr1p2': {
                            'package': {
                                'gr1p2.dep': '',
                                'gr1p2.mem': '',
                            },
                        },
                    },
                    'gr2': {
                        'group': {
                            'gr2.dep': 'gr1',
                            'gr2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_no_mode_error(self):
        with self.assertRaises(InvalidArgumentsError) as e:
            run(None, None, None, None, None, [])
        assert('No mode specified' == e.exception.args[0])

    def test_unknown_mode_error(self):
        with self.assertRaises(InvalidArgumentsError) as e:
            run(None, None, None, None, None, ['foo'])
        assert('Unknown mode \'{}\''.format('foo') == e.exception.args[0])

    def test_target_with_dependencies(self):
        f = StringIO()
        run(f, None, None, None, None, ['walk', 'gr2'])

        r  = TargetResolver(self._config)
        us = resolve(r, ['gr2'])

        assert(' '.join(u.name for u in us) + '\n' == f.getvalue())
Пример #3
0
class RunTest(TestCase):
    def setUp(self):
        self._config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'groups': {
                    'gr1': {
                        'group': {
                            'gr1.dep': '',
                            'gr1.mem': 'gr1p1 gr1p2',
                        },
                        'gr1p1': {
                            'package': {
                                'gr1p1.dep': '',
                                'gr1p1.mem': '',
                            },
                        },
                        'gr1p2': {
                            'package': {
                                'gr1p2.dep': '',
                                'gr1p2.mem': '',
                            },
                        },
                    },
                    'gr2': {
                        'group': {
                            'gr2.dep': 'gr1',
                            'gr2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_no_mode_error(self):
        with self.assertRaises(InvalidArgumentsError) as e:
            run(None, None, None, None, None, [])
        assert ('No mode specified' == e.exception.args[0])

    def test_unknown_mode_error(self):
        with self.assertRaises(InvalidArgumentsError) as e:
            run(None, None, None, None, None, ['foo'])
        assert ('Unknown mode \'{}\''.format('foo') == e.exception.args[0])

    def test_target_with_dependencies(self):
        f = StringIO()
        run(f, None, None, None, None, ['walk', 'gr2'])

        r = TargetResolver(self._config)
        us = resolve(r, ['gr2'])

        assert (' '.join(u.name for u in us) + '\n' == f.getvalue())
Пример #4
0
class GraphTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': '',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_graph(self):
        f = StringIO()
        run(f, None, None, None, None, ['dot', 'p2'])
        lines = f.getvalue().split('\n')
        assert ('digraph G {' == lines[0])
        assert ('    "p2" -> "p1"' == lines[1])
        assert ('}' == lines[2])
Пример #5
0
class CMakeResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'thirdparty': {
                    't1': {
                        'CMakeLists.txt': '',
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_cmake_identification(self):
        r = TargetResolver(self.config)
        assert ({
            'type': 'cmake',
            'path': P('r') / 'thirdparty' / 't1'
        } == r.identify('t1'))

    def test_cmake_path(self):
        r = TargetResolver(self.config)
        t = r.resolve('t1', {})
        assert (P('r') / 'thirdparty' / 't1' == t.path())
Пример #6
0
class CMakeResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'thirdparty': {
                    't1': {
                        'CMakeLists.txt': '',
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_cmake_identification(self):
        r = TargetResolver(self.config)
        assert({
            'type': 'cmake',
            'path': P('r')/'thirdparty'/'t1'
        } == r.identify('t1'))

    def test_cmake_path(self):
        r = TargetResolver(self.config)
        t = r.resolve('t1', {})
        assert(P('r')/'thirdparty'/'t1' == t.path())
Пример #7
0
class NoConfigMainTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
        })

    def tearDown(self):
        self._patcher.reset()

    def test_help_text(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, [__name__])
        assert(not stdout.getvalue())
        assert(stderr.getvalue())

    def test_no_config_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout,
             stderr,
             None,
             None,
             [__name__, 'walk', 'bdemeta.json', 'p1'])
        assert(not stdout.getvalue())
        assert(stderr.getvalue())
Пример #8
0
class GraphTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': '',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_graph(self):
        f = StringIO()
        run(f, None, None, None, None, ['dot', 'p2'])
        lines = f.getvalue().split('\n')
        assert('digraph G {'      == lines[0])
        assert('    "p2" -> "p1"' == lines[1])
        assert('}'                == lines[2])
Пример #9
0
class NoRootTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            'bdemeta.json': '{"roots": ["r"]}',
        })

    def tearDown(self):
        self._patcher.reset()

    def test_no_root_error(self):
        with self.assertRaises(InvalidPathError) as e:
            run(None, None, None, None, ['walk', 'bdemeta.json'])
        assert(P('r') == e.exception.args[0])

    def test_no_root_main_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout,
             stderr,
             None,
             None,
             [__name__, 'walk', 'bdemeta.json', 'p1'])
        assert(not stdout.getvalue())
        assert(stderr.getvalue())
        assert('r' in stderr.getvalue())
Пример #10
0
class PluginTestsTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ],
            'plugin_tests': ['gr2']
        }
        self._patcher = OsPatcher({
            'r': {
                'groups': {
                    'gr1': {
                        'group': {
                            'gr1.dep': '',
                            'gr1.mem': 'gr1p1',
                        },
                        'gr1p1': {
                            'package': {
                                'gr1p1.dep': '',
                                'gr1p1.mem': 'gr1p1_c1',
                            },
                            'gr1p1_c1.cpp': '',
                            'gr1p1_c1.h': '',
                            'gr1p1_c1.t.cpp': '',
                        },
                    },
                    'gr2': {
                        'group': {
                            'gr2.dep': '',
                            'gr2.mem': 'gr2p1',
                        },
                        'gr2p1': {
                            'package': {
                                'gr2p1.dep': '',
                                'gr2p1.mem': 'gr2p1_c1',
                            },
                            'gr2p1_c1.cpp': '',
                            'gr2p1_c1.h': '',
                            'gr2p1_c1.t.cpp': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_non_plugin_tests(self):
        r = TargetResolver(self.config)
        gr1 = r.resolve('gr1', {})
        assert (not gr1.plugin_tests)

    def test_plugin_tests(self):
        r = TargetResolver(self.config)
        gr2 = r.resolve('gr2', {})
        assert (gr2.plugin_tests)
Пример #11
0
class BdeItemsTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            'one': {
                'char': 'a',
                'commented': {
                    'item': '# a',
                },
                'real': {
                    'one': {
                        'comment': 'a\n#b',
                    },
                },
            },
            'longer': {
                'char': 'ab',
            },
            'two': {
                'same': {
                    'line': 'a b',
                },
                'diff': {
                    'lines': 'a\nb',
                },
                'commented': {
                    'same': {
                        'line': '# a b',
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_one_char_item(self):
        assert({'a'} == bde_items(P('one')/'char'))

    def test_longer_char_item(self):
        assert({'ab'} == bde_items(P('longer')/'char'))

    def test_two_items_on_same_line(self):
        assert({'a', 'b'} == bde_items(P('two')/'same'/'line'))

    def test_item_on_each_line(self):
        assert({'a', 'b'} == bde_items(P('two')/'diff'/'lines'))

    def test_one_commented_item(self):
        assert(set() == bde_items(P('one')/'commented'/'item'))

    def test_two_commented_items_same_line(self):
        assert(set() == bde_items(P('two')/'commented'/'same'/'line'))

    def test_one_real_one_comment(self):
        assert({'a'} == bde_items(P('one')/'real'/'one'/'comment'))
Пример #12
0
class BdeItemsTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            'one': {
                'char': 'a',
                'commented': {
                    'item': '# a',
                },
                'real': {
                    'one': {
                        'comment': 'a\n#b',
                    },
                },
            },
            'longer': {
                'char': 'ab',
            },
            'two': {
                'same': {
                    'line': 'a b',
                },
                'diff': {
                    'lines': 'a\nb',
                },
                'commented': {
                    'same': {
                        'line': '# a b',
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_one_char_item(self):
        assert({'a'} == bde_items(P('one')/'char'))

    def test_longer_char_item(self):
        assert({'ab'} == bde_items(P('longer')/'char'))

    def test_two_items_on_same_line(self):
        assert({'a', 'b'} == bde_items(P('two')/'same'/'line'))

    def test_item_on_each_line(self):
        assert({'a', 'b'} == bde_items(P('two')/'diff'/'lines'))

    def test_one_commented_item(self):
        assert(set() == bde_items(P('one')/'commented'/'item'))

    def test_two_commented_items_same_line(self):
        assert(set() == bde_items(P('two')/'commented'/'same'/'line'))

    def test_one_real_one_comment(self):
        assert({'a'} == bde_items(P('one')/'real'/'one'/'comment'))
Пример #13
0
class NoConfigErrorTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({})

    def tearDown(self):
        self._patcher.reset()

    def test_no_config_error(self):
        caught = False
        try:
            run(StringIO(), ['walk', 'foo'])
        except NoConfigError as e:
            caught = True
        assert(caught)
Пример #14
0
class InvalidPathErrorTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{ "roots": ["unlikely_path_that_exists"] }',
        })

    def tearDown(self):
        self._patcher.reset()

    def test_invalid_path_error(self):
        with self.assertRaises(InvalidPathError):
            run(None, None, None, None, None, ['walk', 'foo'])

        stderr = StringIO()
        main(None, stderr, None, None, None, [__name__, 'walk', 'foo'])
        assert(stderr.getvalue())
Пример #15
0
class InvalidPathErrorTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf':
            '{ "roots": ["unlikely_path_that_exists"] }',
        })

    def tearDown(self):
        self._patcher.reset()

    def test_invalid_path_error(self):
        with self.assertRaises(InvalidPathError):
            run(None, None, None, None, None, ['walk', 'foo'])

        stderr = StringIO()
        main(None, stderr, None, None, None, [__name__, 'walk', 'foo'])
        assert (stderr.getvalue())
Пример #16
0
class NotFoundErrorsTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': { },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_non_identification(self):
        r = TargetResolver(self.config)
        with self.assertRaises(TargetNotFoundError):
            r.identify('foo')
Пример #17
0
class NoConfigMainTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({})

    def tearDown(self):
        self._patcher.reset()

    def test_help_text(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__])
        assert (not stdout.getvalue())
        assert (stderr.getvalue())

    def test_no_config_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'walk', 'p1'])
        assert (not stdout.getvalue())
        assert (stderr.getvalue())
Пример #18
0
class CMakeTest(TestCase):
    def setUp(self):
        self._config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'adapters': {
                    'p': {
                        'package': {
                            'p.dep': '',
                            'p.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_generate_cmake(self):
        output = StringIO()

        f1 = {}
        w1 = get_filestore_writer(f1)

        run(output, None, w1, None, None, ['cmake', 'p'])

        r = TargetResolver(self._config)
        p = resolve(r, 'p')
        f2 = {}
        w2 = get_filestore_writer(f2)
        generate(p, w2)

        assert (f1.keys() == f2.keys())
        for k in f1:
            assert (f1[k].getvalue() == f2[k].getvalue())
Пример #19
0
class LazilyBoundTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ],
            'providers': {
                'p1': ['bar']
            },
            'runtime_libraries': [
                'bar'
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': '',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'bar',
                            'p2.mem': '',
                        },
                    }
                },
            }
        })

    def tearDown(self):
        self._patcher.reset()

    def test_lazily_bound_bar(self):
        r   = TargetResolver(self.config)
        p1  = r.resolve('p1',  {})
        bar = r.resolve('bar', { 'p1': p1 })
        p2  = r.resolve('p2',  { 'bar': bar, 'p1': p1 })
        assert(p2.lazily_bound)
Пример #20
0
class CMakeTest(TestCase):
    def setUp(self):
        self._config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'adapters': {
                    'p': {
                        'package': {
                            'p.dep': '',
                            'p.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_generate_cmake(self):
        output = StringIO()

        f1 = {}
        w1 = get_filestore_writer(f1)

        run(output, None, w1, None, None, ['cmake', 'p'])

        r  = TargetResolver(self._config)
        p  = resolve(r, 'p')
        f2 = {}
        w2 = get_filestore_writer(f2)
        generate(p, w2)

        assert(f1.keys() == f2.keys())
        for k in f1:
            assert(f1[k].getvalue() == f2[k].getvalue())
Пример #21
0
class NoRootTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
        })

    def tearDown(self):
        self._patcher.reset()

    def test_no_root_error(self):
        with self.assertRaises(InvalidPathError) as e:
            run(None, None, None, None, None, ['walk'])
        assert (P('r') == e.exception.args[0])

    def test_no_root_main_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'walk', 'p1'])
        assert (not stdout.getvalue())
        assert (stderr.getvalue())
        assert ('r' in stderr.getvalue())
Пример #22
0
class NotFoundErrorsTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {},
        })

    def tearDown(self):
        self._patcher.reset()

    def test_non_identification(self):
        r = TargetResolver(self.config)
        caught = False
        try:
            r.identify('foo')
        except TargetNotFoundError:
            caught = True
        assert (caught)
Пример #23
0
class NotFoundErrorsTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': { },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_non_identification(self):
        r = TargetResolver(self.config)
        caught = False
        try:
            r.identify('foo')
        except TargetNotFoundError:
            caught = True
        assert(caught)
Пример #24
0
class NoConfigErrorTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({})

    def tearDown(self):
        self._patcher.reset()

    def test_no_config_error(self):
        with self.assertRaises(NoConfigError):
            run(None, None, None, None, None, ['walk', 'foo'])

        stderr = StringIO()
        main(None, stderr, None, None, None, [__name__, 'walk', 'foo'])
        assert (stderr.getvalue())

    def test_args_error_if_config_unneeded(self):
        with self.assertRaises(InvalidArgumentsError):
            run(None, None, None, None, None, [])

        stderr = StringIO()
        main(None, stderr, None, None, None, [__name__])
        assert (stderr.getvalue())
Пример #25
0
class NoConfigErrorTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({})

    def tearDown(self):
        self._patcher.reset()

    def test_no_config_error(self):
        with self.assertRaises(NoConfigError):
            run(None, None, None, None, None, ['walk', 'foo'])

        stderr = StringIO()
        main(None, stderr, None, None, None, [__name__, 'walk', 'foo'])
        assert(stderr.getvalue())

    def test_args_error_if_config_unneeded(self):
        with self.assertRaises(InvalidArgumentsError):
            run(None, None, None, None, None, [])

        stderr = StringIO()
        main(None, stderr, None, None, None, [__name__])
        assert(stderr.getvalue())
Пример #26
0
class PkgConfigResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ],
            'pkg_configs': {
                'foo': 'bar',
            },
        }
        self._patcher = OsPatcher({})

    def tearDown(self):
        self._patcher.reset()

    def test_pkg_identification(self):
        r = TargetResolver(self.config)
        assert (Identification('pkg_config', None, 'bar') == r.identify('foo'))

    def test_pkg_name(self):
        r = TargetResolver(self.config)
        t = r.resolve('foo', {})
        assert ('bar' == t.package)
Пример #27
0
class PkgConfigResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ],
            'pkg_configs': {
                'foo': 'bar',
            },
        }
        self._patcher = OsPatcher({
        })

    def tearDown(self):
        self._patcher.reset()

    def test_pkg_identification(self):
        r = TargetResolver(self.config)
        assert(Identification('pkg_config', None, 'bar') == r.identify('foo'))

    def test_pkg_name(self):
        r = TargetResolver(self.config)
        t = r.resolve('foo', {})
        assert('bar' == t.package)
Пример #28
0
class StandaloneResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': 'p1c1 p1c2',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_adapter_identification(self):
        r = TargetResolver(self.config)
        assert ({
            'type': 'package',
            'path': P('r') / 'adapters' / 'p1'
        } == r.identify('p1'))

    def test_standalone_with_one_dependency(self):
        r = TargetResolver(self.config)
        assert (set(['p1']) == r.dependencies('p2'))

    def test_level_one_standalone_resolution(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert ('p1' == p1)

    def test_level_one_standalone_resolution_components(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert ('p1' == p1)

        c1 = P('r') / 'adapters' / 'p1' / 'p1c1.cpp'
        c2 = P('r') / 'adapters' / 'p1' / 'p1c2.cpp'
        assert ([c1, c2] == list(sorted(p1.sources())))

    def test_level_two_group_resolution(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert ('p1' == p1)

        p2 = r.resolve('p2', {'p1': p1})
        assert ('p2' == p2)
Пример #29
0
class StandaloneResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': 'p1c1 p1c2',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_adapter_identification(self):
        r = TargetResolver(self.config)
        assert({
            'type': 'package',
            'path': P('r')/'adapters'/'p1'
        } == r.identify('p1'))

    def test_standalone_with_one_dependency(self):
        r = TargetResolver(self.config)
        assert(set(['p1']) == r.dependencies('p2'))

    def test_level_one_standalone_resolution(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert('p1' == p1)

    def test_level_one_standalone_resolution_components(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert('p1' == p1)

        c1 = P('r')/'adapters'/'p1'/'p1c1.cpp'
        c2 = P('r')/'adapters'/'p1'/'p1c2.cpp'
        assert([c1, c2] == list(sorted(p1.sources())))

    def test_level_two_group_resolution(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert('p1' == p1)

        p2 = r.resolve('p2', { 'p1': p1 })
        assert('p2' == p2)
Пример #30
0
class TargetResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'groups': {
                    'gr1': {
                        'group': {
                            'gr1.dep': '',
                            'gr1.mem': 'gr1p1 gr1p2',
                        },
                        'gr1p1': {
                            'package': {
                                'gr1p1.dep': '',
                                'gr1p1.mem': '',
                            },
                        },
                        'gr1p2': {
                            'package': {
                                'gr1p2.dep': '',
                                'gr1p2.mem': '',
                            },
                        },
                    },
                    'gr2': {
                        'group': {
                            'gr2.dep': 'gr1',
                            'gr2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_group_identification(self):
        r = TargetResolver(self.config)
        assert({
            'type': 'group',
            'path': P('r')/'groups'/'gr1'
        } == r.identify('gr1'))

    def test_group_with_one_dependency(self):
        r = TargetResolver(self.config)
        assert(set(['gr1']) == r.dependencies('gr2'))

    def test_level_one_group_resolution(self):
        r = TargetResolver(self.config)

        gr1 = r.resolve('gr1', {})
        assert('gr1' == gr1)

    def test_level_one_group_resolution_packages(self):
        ur = TargetResolver(self.config)
        pr = PackageResolver(P('r')/'groups'/'gr1')

        gr1 = ur.resolve('gr1', {})
        assert('gr1' == gr1)
        assert(resolve(pr, ['gr1p1', 'gr1p2']) == gr1._packages)

    def test_level_two_group_resolution(self):
        r = TargetResolver(self.config)

        gr1 = r.resolve('gr1', {})
        gr2 = r.resolve('gr2', { 'gr1': gr1 })
        assert('gr2' == gr2)
Пример #31
0
class PackageResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'g1': {
                    'g1p1': {
                        'package': {
                            'g1p1.dep': '',
                            'g1p1.mem': '',
                        },
                    },
                    'g1p2': {
                        'package': {
                            'g1p2.dep': '',
                            'g1p2.mem': 'g1p2_c1',
                        },
                    },
                    'g1p3': {
                        'package': {
                            'g1p3.dep': '',
                            'g1p3.mem': 'g1p3_c1',
                        },
                        'g1p3_c1.t.cpp': '',
                        'g1p3_c1.h':     '',
                    },
                    'g1+p4': {
                        'package': {
                            'g1+p4.dep': '',
                            'g1+p4.mem': '',
                        },
                        'a.cpp': '',
                        'b.cpp': '',
                    },
                    'g1+p5': {
                        'package': {
                            'g1+p5.dep': '',
                            'g1+p5.mem': '',
                        },
                        'a.c': '',
                    },
                    'g1+p6': {
                        'package': {
                            'g1+p6.dep': '',
                            'g1+p6.mem': '',
                        },
                        'a.x': '',
                    },
                },
                'g2': {
                    'g2p1': {
                        'package': {
                            'g2p1.dep': '',
                            'g2p1.mem': '',
                        },
                    },
                    'g2p2': {
                        'package': {
                            'g2p2.dep': 'g2p1',
                            'g2p2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_empty_dependencies(self):
        r = PackageResolver(P('r')/'g1')
        assert(set() == r.dependencies('g1p1'))

    def test_non_empty_dependencies(self):
        r = PackageResolver(P('r')/'g2')
        assert(set(['g2p1']) == r.dependencies('g2p2'))

    def test_empty_package(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1p1', {})
        assert('g1p1'               == p)
        assert([]                   == p.dependencies())
        assert([P('r')/'g1'/'g1p1'] == list(p.includes()))
        assert([]                   == list(p.sources()))

    def test_one_non_driver_component(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1p2', {})
        assert('g1p2'                             == p)
        assert([]                                 == p.dependencies())
        assert([P('r')/'g1'/'g1p2']               == list(p.includes()))
        assert([P('r')/'g1'/'g1p2'/'g1p2_c1.cpp'] == list(p.sources()))
        assert([]                                 == list(p.drivers()))

    def test_one_driver_component(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1p3', {})
        assert('g1p3'                               == p)
        assert([]                                   == p.dependencies())
        assert([P('r')/'g1'/'g1p3']                 == list(p.includes()))
        assert([P('r')/'g1'/'g1p3'/'g1p3_c1.h']     == list(p.headers()))
        assert([P('r')/'g1'/'g1p3'/'g1p3_c1.cpp']   == list(p.sources()))
        assert([P('r')/'g1'/'g1p3'/'g1p3_c1.t.cpp'] == list(p.drivers()))

    def test_empty_package_with_dependency(self):
        r = PackageResolver(P('r')/'g2')

        p1 = r.resolve('g2p1', {})
        assert('g2p1' == p1)
        assert([]     == p1.dependencies())

        p2 = r.resolve('g2p2', { 'g2p1': p1 })
        assert('g2p2' == p2)
        assert([p1]   == p2.dependencies())

    def test_thirdparty_package_lists_cpps(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p4', {})

        assert('g1+p4'               == p)
        assert([]                    == p.dependencies())
        assert([P('r')/'g1'/'g1+p4'] == list(p.includes()))

        assert(2                           == len(list(p.sources())))
        assert(P('r')/'g1'/'g1+p4'/'a.cpp' in list(p.sources()))
        assert(P('r')/'g1'/'g1+p4'/'b.cpp' in list(p.sources()))

    def test_thirdparty_package_lists_cs(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p5', {})
        assert('g1+p5'                     == p)
        assert([]                          == p.dependencies())
        assert([P('r')/'g1'/'g1+p5']       == list(p.includes()))
        assert([P('r')/'g1'/'g1+p5'/'a.c'] == list(p.sources()))

    def test_thirdparty_package_ignores_non_c_non_cpp(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p6', {})
        assert('g1+p6'               == p)
        assert([]                    == p.dependencies())
        assert([P('r')/'g1'/'g1+p6'] == list(p.includes()))
        assert([]                    == list(p.sources()))

    def test_level_two_package_has_dependency(self):
        r = PackageResolver(P('r')/'g2')

        p1 = r.resolve('g2p1', {})
        assert('g2p1'               == p1)
        assert([]                   == p1.dependencies())
        assert([P('r')/'g2'/'g2p1'] == list(p1.includes()))
        assert(0                    == len(list(p1.sources())))

        p2 = r.resolve('g2p2', { 'g2p1': p1 })
        assert('g2p2'               == p2)
        assert([p1]                 == p2.dependencies())
        assert([P('r')/'g2'/'g2p2'] == list(p2.includes()))
        assert([]                   == list(p2.sources()))
Пример #32
0
class PackageResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'g1': {
                    'g1p1': {
                        'package': {
                            'g1p1.dep': '',
                            'g1p1.mem': '',
                        },
                    },
                    'g1p2': {
                        'package': {
                            'g1p2.dep': '',
                            'g1p2.mem': 'g1p2_c1',
                        },
                    },
                    'g1p3': {
                        'package': {
                            'g1p3.dep': '',
                            'g1p3.mem': 'g1p3_c1',
                        },
                        'g1p3_c1.t.cpp': '',
                        'g1p3_c1.h':     '',
                    },
                    'g1+p4': {
                        'package': {
                            'g1+p4.dep': '',
                            'g1+p4.mem': '',
                        },
                        'a.cpp': '',
                        'b.cpp': '',
                    },
                    'g1+p5': {
                        'package': {
                            'g1+p5.dep': '',
                            'g1+p5.mem': '',
                        },
                        'a.c': '',
                    },
                    'g1+p6': {
                        'package': {
                            'g1+p6.dep': '',
                            'g1+p6.mem': '',
                        },
                        'a.x': '',
                    },
                    'g1+p7': {
                        'package': {
                            'g1+p7.dep': '',
                            'g1+p7.mem': '',
                        },
                        'a.h': '',
                    },
                },
                'g2': {
                    'g2p1': {
                        'package': {
                            'g2p1.dep': '',
                            'g2p1.mem': '',
                        },
                    },
                    'g2p2': {
                        'package': {
                            'g2p2.dep': 'g2p1',
                            'g2p2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_empty_dependencies(self):
        r = PackageResolver(P('r')/'g1')
        assert(set() == r.dependencies('g1p1'))

    def test_non_empty_dependencies(self):
        r = PackageResolver(P('r')/'g2')
        assert(set(['g2p1']) == r.dependencies('g2p2'))

    def test_empty_package(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1p1', {})
        assert('g1p1'                    == p.name)
        assert([]                        == p.dependencies())
        assert([str(P('r')/'g1'/'g1p1')] == list(p.includes()))
        assert([]                        == list(p.sources()))

    def test_one_non_driver_component(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1p2', {})
        assert('g1p2'                                  == p.name)
        assert([]                                      == p.dependencies())
        assert([str(P('r')/'g1'/'g1p2')]               == list(p.includes()))
        assert([str(P('r')/'g1'/'g1p2'/'g1p2_c1.cpp')] == list(p.sources()))
        assert([]                                      == list(p.drivers()))

    def test_one_driver_component(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1p3', {})
        assert('g1p3'                                    == p.name)
        assert([]                                        == p.dependencies())
        assert([str(P('r')/'g1'/'g1p3')]                 == list(p.includes()))
        assert([str(P('r')/'g1'/'g1p3'/'g1p3_c1.h')]     == list(p.headers()))
        assert([str(P('r')/'g1'/'g1p3'/'g1p3_c1.cpp')]   == list(p.sources()))
        assert([str(P('r')/'g1'/'g1p3'/'g1p3_c1.t.cpp')] == list(p.drivers()))

    def test_empty_package_with_dependency(self):
        r = PackageResolver(P('r')/'g2')

        p1 = r.resolve('g2p1', {})
        assert('g2p1' == p1.name)
        assert([]     == p1.dependencies())

        p2 = r.resolve('g2p2', { 'g2p1': p1 })
        assert('g2p2' == p2.name)
        assert([p1]   == p2.dependencies())

    def test_thirdparty_package_lists_cpps(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p4', {})

        assert('g1+p4'                    == p.name)
        assert([]                         == p.dependencies())
        assert([str(P('r')/'g1'/'g1+p4')] == list(p.includes()))

        assert(2                                == len(list(p.sources())))
        assert(str(P('r')/'g1'/'g1+p4'/'a.cpp') in list(p.sources()))
        assert(str(P('r')/'g1'/'g1+p4'/'b.cpp') in list(p.sources()))

    def test_thirdparty_package_lists_cs(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p5', {})
        assert('g1+p5'                          == p.name)
        assert([]                               == p.dependencies())
        assert([str(P('r')/'g1'/'g1+p5')]       == list(p.includes()))
        assert([str(P('r')/'g1'/'g1+p5'/'a.c')] == list(p.sources()))

    def test_thirdparty_package_ignores_non_c_non_cpp(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p6', {})
        assert('g1+p6'                    == p.name)
        assert([]                         == p.dependencies())
        assert([str(P('r')/'g1'/'g1+p6')] == list(p.includes()))
        assert([]                         == list(p.sources()))

    def test_thirdparty_package_with_header(self):
        r = PackageResolver(P('r')/'g1')
        p = r.resolve('g1+p7', {})
        assert('g1+p7'                          == p.name)
        assert([]                               == p.dependencies())
        assert([str(P('r')/'g1'/'g1+p7')]       == list(p.includes()))
        assert([str(P('r')/'g1'/'g1+p7'/'a.h')] == list(p.headers()))

    def test_level_two_package_has_dependency(self):
        r = PackageResolver(P('r')/'g2')

        p1 = r.resolve('g2p1', {})
        assert('g2p1'                    == p1.name)
        assert([]                        == p1.dependencies())
        assert([str(P('r')/'g2'/'g2p1')] == list(p1.includes()))
        assert(0                         == len(list(p1.sources())))

        p2 = r.resolve('g2p2', { 'g2p1': p1 })
        assert('g2p2'                    == p2.name)
        assert([p1]                      == p2.dependencies())
        assert([str(P('r')/'g2'/'g2p2')] == list(p2.includes()))
        assert([]                        == list(p2.sources()))
Пример #33
0
class MainTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': '',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                    'p3': {
                        'package': {
                            'p3.dep': 'p4',
                            'p3.mem': '',
                        },
                    },
                    'p4': {
                        'package': {
                            'p4.dep': 'p3',
                            'p4.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_walk(self):
        stdout = StringIO()
        main(stdout, None, None, None, None, [None, 'walk', 'p2'])
        assert ('p2 p1\n' == stdout.getvalue())

    def test_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'foo'])
        assert (not stdout.getvalue())
        assert (stderr.getvalue())

    def test_cyclic_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'walk', 'p3'])
        assert (not stdout.getvalue())
        assert (stderr.getvalue())
        assert ('p3' in stderr.getvalue())
        assert ('p4' in stderr.getvalue())

    def test_not_found_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'walk', 'p5'])
        assert (not stdout.getvalue())
        assert (stderr.getvalue())
        assert ('p5' in stderr.getvalue())
Пример #34
0
class MainTest(TestCase):
    def setUp(self):
        self._patcher = OsPatcher({
            '.bdemeta.conf': '{"roots": ["r"]}',
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': '',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                    'p3': {
                        'package': {
                            'p3.dep': 'p4',
                            'p3.mem': '',
                        },
                    },
                    'p4': {
                        'package': {
                            'p4.dep': 'p3',
                            'p4.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_walk(self):
        stdout = StringIO()
        main(stdout, None, None, None, None, [None, 'walk', 'p2'])
        assert('p2 p1\n' == stdout.getvalue())

    def test_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'foo'])
        assert(not stdout.getvalue())
        assert(stderr.getvalue())

    def test_cyclic_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'walk', 'p3'])
        assert(not stdout.getvalue())
        assert(stderr.getvalue())
        assert('p3' in stderr.getvalue())
        assert('p4' in stderr.getvalue())

    def test_not_found_error(self):
        stdout = StringIO()
        stderr = StringIO()
        main(stdout, stderr, None, None, None, [__name__, 'walk', 'p5'])
        assert(not stdout.getvalue())
        assert(stderr.getvalue())
        assert('p5' in stderr.getvalue())
Пример #35
0
class StandaloneResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'adapters': {
                    'p1': {
                        'package': {
                            'p1.dep': '',
                            'p1.mem': 'p1c1 p1c2',
                        },
                    },
                    'p2': {
                        'package': {
                            'p2.dep': 'p1',
                            'p2.mem': '',
                        },
                    },
                    'p3': {
                        'package': {
                            'p3.dep': '',
                            'p3.mem': '',
                        },
                        'p3.cmake': '',
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_adapter_identification(self):
        r = TargetResolver(self.config)
        assert(Identification('package', P('r')/'adapters'/'p1') == \
                                                              r.identify('p1'))

    def test_standalone_with_one_dependency(self):
        r = TargetResolver(self.config)
        assert(set(['p1']) == r.dependencies('p2'))

    def test_level_one_standalone_resolution(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert('p1' == p1.name)

    def test_level_one_standalone_resolution_components(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert('p1' == p1.name)

        c1 = P('r')/'adapters'/'p1'/'p1c1.cpp'
        c2 = P('r')/'adapters'/'p1'/'p1c2.cpp'
        assert([str(c1), str(c2)] == list(sorted(p1.sources())))

    def test_level_two_group_resolution(self):
        r = TargetResolver(self.config)

        p1 = r.resolve('p1', {})
        assert('p1' == p1.name)

        p2 = r.resolve('p2', { 'p1': p1 })
        assert('p2' == p2.name)

    def test_package_cmake_overrides(self):
        r = TargetResolver(self.config)

        p3 = r.resolve('p3', {})
        assert('p3' == p3.name)
        assert(str(P('r')/'adapters'/'p3'/'p3.cmake') == p3.overrides)
Пример #36
0
class ApplicationResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'applications': {
                    'app1': {
                        'package': {
                            'app1.mem': 'app1.m',
                            'app1.dep': 'gr1'
                        },
                        'app1.m.cpp': ''
                    },
                    'app2': {
                        'package': {
                            'app2.mem': '',
                            'app2.dep': 'gr1'
                        },
                        'app2.m.cpp': ''
                    },
                },
                'groups': {
                    'gr1': {
                        'group': {
                            'gr1.dep': '',
                            'gr1.mem': 'gr1p1 gr1p2',
                        },
                        'gr1p1': {
                            'package': {
                                'gr1p1.dep': '',
                                'gr1p1.mem': '',
                            },
                        },
                        'gr1p2': {
                            'package': {
                                'gr1p2.dep': '',
                                'gr1p2.mem': '',
                            },
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_application_identification(self):
        r = TargetResolver(self.config)
        assert(Identification('application', P('r')/'applications'/'app1') == \
                                                            r.identify('app1'))

    def test_application_with_one_dependency(self):
        r = TargetResolver(self.config)
        assert (set(['gr1']) == r.dependencies('app1'))

    def test_application_resolution_explicit_member(self):
        r = TargetResolver(self.config)

        gr1 = r.resolve('gr1', {})
        app1 = r.resolve('app1', {'gr1': gr1})
        assert ('app1' == app1.name)
        assert (gr1 in app1.dependencies())
        main_file = P('r') / 'applications' / 'app1' / 'app1.m.cpp'
        assert (str(main_file) in app1.sources())

    def test_application_resolution_implicit_member(self):
        r = TargetResolver(self.config)

        gr1 = r.resolve('gr1', {})
        app2 = r.resolve('app2', {'gr1': gr1})
        assert ('app2' == app2.name)
        assert (gr1 in app2.dependencies())
        main_file = P('r') / 'applications' / 'app2' / 'app2.m.cpp'
        assert (str(main_file) in app2.sources())
Пример #37
0
class TargetResolverTest(TestCase):
    def setUp(self):
        self.config = {
            'roots': [
                P('r'),
            ]
        }
        self._patcher = OsPatcher({
            'r': {
                'groups': {
                    'gr1': {
                        'group': {
                            'gr1.dep': '',
                            'gr1.mem': 'gr1p1 gr1p2',
                        },
                        'gr1p1': {
                            'package': {
                                'gr1p1.dep': '',
                                'gr1p1.mem': '',
                            },
                        },
                        'gr1p2': {
                            'package': {
                                'gr1p2.dep': '',
                                'gr1p2.mem': '',
                            },
                        },
                    },
                    'gr2': {
                        'group': {
                            'gr2.dep': 'gr1',
                            'gr2.mem': '',
                        },
                    },
                },
            },
        })

    def tearDown(self):
        self._patcher.reset()

    def test_group_identification(self):
        r = TargetResolver(self.config)
        assert(Identification('group', P('r')/'groups'/'gr1') == \
                                                             r.identify('gr1'))

    def test_group_with_one_dependency(self):
        r = TargetResolver(self.config)
        assert(set(['gr1']) == r.dependencies('gr2'))

    def test_level_one_group_resolution(self):
        r = TargetResolver(self.config)

        gr1 = r.resolve('gr1', {})
        assert('gr1' == gr1.name)

    def test_level_one_group_resolution_packages(self):
        ur = TargetResolver(self.config)
        pr = PackageResolver(P('r')/'groups'/'gr1')

        gr1 = ur.resolve('gr1', {})
        assert('gr1' == gr1.name)
        assert([p.name for p in resolve(pr, ['gr1p1', 'gr1p2'])] == \
                                               [p.name for p in gr1._packages])

    def test_level_two_group_resolution(self):
        r = TargetResolver(self.config)

        gr1 = r.resolve('gr1', {})
        gr2 = r.resolve('gr2', { 'gr1': gr1 })
        assert('gr2' == gr2.name)