Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements for tests refactor #588

Merged
merged 3 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import re
import shutil
import subprocess
from contextlib import contextmanager
from pathlib import Path

import pytest
Expand All @@ -26,6 +25,7 @@

src_dir = Path(__file__).parent.parent
conan_provider = src_dir / "conan_provider.cmake"
resources_dir= src_dir / 'tests' / 'resources'

unix = pytest.mark.skipif(platform.system() != "Linux" and platform.system() != "Darwin", reason="Linux or Darwin only")
linux = pytest.mark.skipif(platform.system() != "Linux", reason="Linux only")
Expand Down Expand Up @@ -66,16 +66,16 @@ def setup_conan_home(conan_home_dir, tmp_path_factory):

# libbye with modified conanfile.py (custom package_info properties)
run("conan new cmake_lib -d name=bye -d version=0.1 -f -vquiet")
shutil.copy2(src_dir / 'tests' / 'resources' / 'libbye' / 'conanfile.py', ".")
shutil.copy2(resources_dir / 'libbye' / 'conanfile.py', ".")
run("conan export . -vquiet")

# libboost with modified conanfile.py (ensure upper case B cmake package name)
run("conan new cmake_lib -d name=boost -d version=1.77.0 -f -vquiet")
shutil.copy2(src_dir / 'tests' / 'resources' / 'fake_boost_recipe' / 'conanfile.py', ".")
shutil.copy2(resources_dir / 'fake_boost_recipe' / 'conanfile.py', ".")
run("conan export . -vquiet")

# Additional profiles for testing
config_dir = src_dir / 'tests' / 'resources' / 'custom_config'
config_dir = resources_dir / 'custom_config'
run(f"conan config install {config_dir}")
os.chdir(cwd)

Expand All @@ -86,7 +86,7 @@ def setup_cmake_workdir(base_tmp_dir, resource_dirs=['basic_cmake']):
source_dir.mkdir()
binary_dir.mkdir()
for item in resource_dirs:
shutil.copytree(src_dir / 'tests' / 'resources' / item, source_dir.as_posix(), dirs_exist_ok=True)
shutil.copytree(resources_dir / item, source_dir.as_posix(), dirs_exist_ok=True)
return (source_dir, binary_dir)

@pytest.fixture
Expand Down Expand Up @@ -240,7 +240,7 @@ class TestFindModules:
def test_find_module(self, capfd, basic_cmake_project):
"Ensure that a call to find_package(XXX MODULE REQUIRED) is honoured by the dependency provider"
source_dir, binary_dir = basic_cmake_project
shutil.copytree(src_dir / 'tests' / 'resources' / 'find_module', source_dir, dirs_exist_ok=True)
shutil.copytree(resources_dir / 'find_module' / 'basic_module', source_dir, dirs_exist_ok=True)

run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release", check=False)
out, err = capfd.readouterr()
Expand All @@ -253,7 +253,7 @@ def test_find_builtin_module(self, capfd, use_find_components, basic_cmake_proje
"Ensure that a Conan-provided -config.cmake file satisfies dependency, even when a CMake builtin "
"exists for the same dependency"
source_dir, binary_dir = basic_cmake_project
shutil.copytree(src_dir / 'tests' / 'resources' / 'find_module_builtin', source_dir, dirs_exist_ok=True)
shutil.copytree(resources_dir / 'find_module' / 'builtin_module', source_dir, dirs_exist_ok=True)
boost_find_components = "ON" if use_find_components else "OFF"
run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release -D_TEST_BOOST_FIND_COMPONENTS={boost_find_components}", check=False)
out, err = capfd.readouterr()
Expand All @@ -263,7 +263,7 @@ def test_find_builtin_module(self, capfd, use_find_components, basic_cmake_proje
def test_cmake_builtin_module(self, capfd, basic_cmake_project):
"Ensure that the Find<PackageName>.cmake modules from the CMake install work"
source_dir, binary_dir = basic_cmake_project
shutil.copytree(src_dir / 'tests' / 'resources' / 'cmake_builtin_module', source_dir, dirs_exist_ok=True)
shutil.copytree(resources_dir / 'find_module' / 'cmake_builtin_module', source_dir, dirs_exist_ok=True)

run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release")
out, _ = capfd.readouterr()
Expand Down Expand Up @@ -326,7 +326,7 @@ def test_profile_composed_list(self, capfd, basic_cmake_project):
def test_profile_pass_path(self, capfd, basic_cmake_project):
"""Test that we can both skip autodetected profile and override with a full profile from a path"""
source_dir, binary_dir = basic_cmake_project
custom_profile = Path(__file__).parent.parent / 'tests' / 'resources' / 'custom_profiles' / 'invalid_os'
custom_profile = resources_dir / 'custom_profiles' / 'invalid_os'
custom_profile = custom_profile.as_posix()
run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release -DCONAN_HOST_PROFILE="{custom_profile}"', check=False)
out, err = capfd.readouterr()
Expand Down