コード例 #1
0
    def test_cmake_with_existing_header(self):
        """Test that cmake can generate flags."""
        test_file_path = path.join(
            path.dirname(__file__), 'cmake_tests', 'lib', 'a.h')

        path_to_file_folder = path.dirname(test_file_path)
        expected_lib_include = Flag('-I', path_to_file_folder)
        cmake_file = CMakeFile(
            ['-I', '-isystem'],
            prefix_paths=None,
            flags=None,
            cmake_binary="cmake",
            header_to_source_mapping=[],
            target_compilers={}
        )
        flags = cmake_file.get_flags(test_file_path)
        db = CompilationDb(
            ['-I', '-isystem'],
            header_to_source_map=[],)
        self.assertEqual(flags[0], Flag('', '-Dliba_EXPORTS'))
        self.assertIn(test_file_path, cmake_file._cache)
        expected_cmake_file = path.join(
            path.dirname(path_to_file_folder), CMakeFile._FILE_NAME)
        found_cmake_file = cmake_file._cache[test_file_path]
        self.assertEqual(expected_cmake_file, found_cmake_file)
        used_db_path = cmake_file._cache[found_cmake_file]
        used_db = db._cache[used_db_path]
        self.assertIn(expected_lib_include, used_db['all'])
コード例 #2
0
    def test_cmake_with_existing_header(self):
        """Test that cmake can generate flags."""
        test_file_path = path.join(path.dirname(__file__), 'cmake_tests',
                                   'lib', 'a.h')

        path_to_file_folder = path.dirname(test_file_path)
        expected_lib_include = Flag('-I', path_to_file_folder)
        cmake_file = CMakeFile(['-I', '-isystem'],
                               prefix_paths=None,
                               flags=None,
                               cmake_binary="cmake",
                               header_to_source_mapping=[],
                               target_compilers={},
                               lazy_flag_parsing=False)
        flags = cmake_file.get_flags(test_file_path)
        db = CompilationDb(['-I', '-isystem'],
                           header_to_source_map=[],
                           lazy_flag_parsing=False)
        self.assertEqual(flags[0], Flag('', '-Dliba_EXPORTS'))
        self.assertIn(test_file_path, cmake_file._cache)
        expected_cmake_file = path.join(path.dirname(path_to_file_folder),
                                        CMakeFile._FILE_NAME)
        found_cmake_file = cmake_file._cache[test_file_path]
        self.assertEqual(expected_cmake_file, found_cmake_file)
        used_db_path = cmake_file._cache[found_cmake_file]
        used_db = db._cache[used_db_path]
        self.assertIn(expected_lib_include, used_db['all'])
コード例 #3
0
    def test_cmake_fail(self):
        """Test behavior when no CMakeLists.txt found."""
        test_file_path = path.join(path.dirname(__file__), 'cmake_tests',
                                   'test_a.cpp')

        folder_with_no_cmake = path.dirname(__file__)
        cmake_file = CMakeFile(['-I', '-isystem'], None, None)
        wrong_scope = SearchScope(from_folder=folder_with_no_cmake)
        flags = cmake_file.get_flags(test_file_path, wrong_scope)
        self.assertTrue(flags is None)
コード例 #4
0
    def test_cmake_generate(self):
        """Test that cmake can generate flags."""
        test_file_path = path.join(path.dirname(__file__), 'cmake_tests',
                                   'test_a.cpp')

        path_to_cmake_proj = path.dirname(test_file_path)
        cmake_file = CMakeFile(['-I', '-isystem'], None, None)
        expected_lib = path.join(path_to_cmake_proj, 'lib')
        flags = cmake_file.get_flags(test_file_path)
        self.assertEqual(flags[0], Flag('-I' + expected_lib))
        self.assertIn(test_file_path, cmake_file._cache)
        expected_cmake_file = path.join(path_to_cmake_proj,
                                        CMakeFile._FILE_NAME)
        found_cmake_file = cmake_file._cache[test_file_path]
        self.assertEqual(expected_cmake_file, found_cmake_file)
コード例 #5
0
    def test_cmake_fail(self):
        """Test behavior when no CMakeLists.txt found."""
        test_file_path = path.join(path.dirname(__file__), 'cmake_tests',
                                   'test_a.cpp')

        folder_with_no_cmake = path.dirname(__file__)
        cmake_file = CMakeFile(['-I', '-isystem'],
                               prefix_paths=None,
                               flags=None,
                               cmake_binary="cmake",
                               header_to_source_mapping=[],
                               target_compilers={})
        wrong_scope = SearchScope(from_folder=folder_with_no_cmake)
        flags = cmake_file.get_flags(test_file_path, wrong_scope)
        self.assertTrue(flags is None)
コード例 #6
0
    def test_cmake_fail(self):
        """Test behavior when no CMakeLists.txt found."""
        test_file_path = path.join(
            path.dirname(__file__), 'cmake_tests', 'test_a.cpp')

        folder_with_no_cmake = path.dirname(__file__)
        cmake_file = CMakeFile(
            ['-I', '-isystem'],
            prefix_paths=None,
            flags=None,
            cmake_binary="cmake",
            header_to_source_mapping=[],
            target_compilers={}
        )
        wrong_scope = SearchScope(from_folder=folder_with_no_cmake)
        flags = cmake_file.get_flags(test_file_path, wrong_scope)
        self.assertTrue(flags is None)
コード例 #7
0
    def test_cmake_with_existing_header(self):
        """Test that cmake can generate flags."""
        test_file_path = path.join(path.dirname(__file__), 'cmake_tests',
                                   'lib', 'a.h')

        path_to_file_folder = path.dirname(test_file_path)
        expected_lib_include = Flag('-I' + path_to_file_folder)
        cmake_file = CMakeFile(['-I', '-isystem'], None, None)
        flags = cmake_file.get_flags(test_file_path)
        db = CompilationDb(['-I', '-isystem'])
        self.assertEqual(flags[0], Flag('-Dliba_EXPORTS'))
        self.assertIn(test_file_path, cmake_file._cache)
        expected_cmake_file = path.join(path.dirname(path_to_file_folder),
                                        CMakeFile._FILE_NAME)
        found_cmake_file = cmake_file._cache[test_file_path]
        self.assertEqual(expected_cmake_file, found_cmake_file)
        used_db_path = cmake_file._cache[found_cmake_file]
        used_db = db._cache[used_db_path]
        self.assertIn(expected_lib_include, used_db['all'])
コード例 #8
0
    def test_cmake_generate(self):
        """Test that cmake can generate flags."""
        test_file_path = path.join(path.dirname(__file__), 'cmake_tests',
                                   'test_a.cpp')

        path_to_cmake_proj = path.dirname(test_file_path)
        cmake_file = CMakeFile(['-I', '-isystem'],
                               prefix_paths=None,
                               flags=None,
                               cmake_binary="cmake",
                               header_to_source_mapping=[],
                               target_compilers={})
        expected_lib = path.join(path_to_cmake_proj, 'lib')
        flags = cmake_file.get_flags(test_file_path)
        self.assertEqual(flags[0], Flag('-I' + expected_lib))
        self.assertIn(test_file_path, cmake_file._cache)
        expected_cmake_file = path.join(path_to_cmake_proj,
                                        CMakeFile._FILE_NAME)
        found_cmake_file = cmake_file._cache[test_file_path]
        self.assertEqual(expected_cmake_file, found_cmake_file)
コード例 #9
0
    def test_cmake_generate(self):
        """Test that cmake can generate flags."""
        test_file_path = path.join(
            path.dirname(__file__), 'cmake_tests', 'test_a.cpp')

        path_to_cmake_proj = path.dirname(test_file_path)
        cmake_file = CMakeFile(
            ['-I', '-isystem'],
            prefix_paths=None,
            flags=None,
            cmake_binary="cmake",
            header_to_source_mapping=[],
            target_compilers={}
        )
        expected_lib = path.join(path_to_cmake_proj, 'lib')
        flags = cmake_file.get_flags(test_file_path)
        self.assertEqual(flags[0], Flag('-I', expected_lib))
        self.assertIn(test_file_path, cmake_file._cache)
        expected_cmake_file = path.join(
            path_to_cmake_proj, CMakeFile._FILE_NAME)
        found_cmake_file = cmake_file._cache[test_file_path]
        self.assertEqual(expected_cmake_file, found_cmake_file)