Skip to content

Commit

Permalink
Port package_identification tests from colcon_core
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay committed Nov 22, 2024
1 parent 8a69a89 commit fb3581b
Showing 1 changed file with 82 additions and 0 deletions.
82 changes: 82 additions & 0 deletions test/test_package_identification_cmake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2016-2018 Dirk Thomas
# Copyright 2024 Open Source Robotics Foundation, Inc.
# Licensed under the Apache License, Version 2.0

from pathlib import Path
from tempfile import TemporaryDirectory

from colcon_core.package_descriptor import PackageDescriptor
from colcon_cmake.package_identification.cmake \
import CmakePackageIdentification
import pytest


def test_identify():
extension = CmakePackageIdentification()

with TemporaryDirectory(prefix='test_colcon_') as basepath:
desc = PackageDescriptor(basepath)
desc.type = 'other'
assert extension.identify(desc) is None
assert desc.name is None

desc.type = None
assert extension.identify(desc) is None
assert desc.name is None
assert desc.type is None

basepath = Path(basepath)
(basepath / 'CMakeLists.txt').write_text('')
assert extension.identify(desc) is None
assert desc.name == basepath.name
assert desc.type == 'cmake'

desc = PackageDescriptor(basepath)
(basepath / 'CMakeLists.txt').write_text(
'cmake_minimum_required(VERSION 3.10)\n'
'project(Project NONE)\n')
assert extension.identify(desc) is None
assert desc.name == 'Project'
assert desc.type == 'cmake'

desc = PackageDescriptor(basepath)
(basepath / 'CMakeLists.txt').write_text(
'cmake_minimum_required(VERSION 3.10)\n'
'project(Project NONE)\n'
'catkin_workspace()\n')
assert extension.identify(desc) is None
assert desc.name is None
assert desc.type is None

desc = PackageDescriptor(basepath)
(basepath / 'CMakeLists.txt').write_text(
'cmake_minimum_required(VERSION 3.10)\n'
'project(pkg-name NONE)\n')
assert extension.identify(desc) is None
assert desc.name == 'pkg-name'
assert desc.type == 'cmake'
assert set(desc.dependencies.keys()) == {'build', 'run'}
assert not desc.dependencies['build']
assert not desc.dependencies['run']
assert extension.identify(desc) is None
assert desc.name == 'pkg-name'
assert desc.type == 'cmake'

desc = PackageDescriptor(basepath)
(basepath / 'CMakeLists.txt').write_text(
'cmake_minimum_required(VERSION 3.10)\n'
'project(other-name NONE)\n'
'find_package(PkgConfig REQUIRED)\n'
'pkg_check_modules(DEP_NAME REQUIRED dep-name>=1.1)\n'
'add_subdirectory(src)\n')
(basepath / 'src').mkdir(parents=True, exist_ok=True)
(basepath / 'src' / 'CMakeLists.txt').write_text(
'find_package(dep-name2 REQUIRED)\n')
(basepath / 'src' / 'README.txt').write_text(
'find_package(other-dep-name REQUIRED)\n')
assert extension.identify(desc) is None
assert desc.name == 'other-name'
assert desc.type == 'cmake'
assert set(desc.dependencies.keys()) == {'build', 'run'}
assert desc.dependencies['build'] == {'dep-name', 'dep-name2', 'PkgConfig'}
assert desc.dependencies['run'] == {'dep-name', 'dep-name2', 'PkgConfig'}

0 comments on commit fb3581b

Please sign in to comment.