Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def build(self):


# needs at least 3.23.3 because of error with "empty identity"
# https://stackoverflow.com/questions/72746725/xcode-14-beta-cmake-not-able-to-resolve-cmake-c-compiler-and-cmake-cxx-compiler
# https://stackoverflow.com/questions/72746725/xcode-14-beta-cmake-not-able-to-resolve-cmake-c-compiler-and-cmake-cxx-compiler
@pytest.mark.skipif(platform.system() != "Darwin", reason="Only OSX")
@pytest.mark.tool("cmake", "3.23")
def test_apple_framework_xcode(client):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import platform
import shutil
import textwrap

Expand Down Expand Up @@ -280,27 +279,6 @@ def test_standard_names(setup_client_with_greetings):

create_chat(client, "standard", package_info, cmake_find, test_cmake_find)

# Test consumer multi-config
if platform.system() == "Windows":
with client.chdir("test_package"):
# FIXME This doesn't work because test_package requires has been disabled
return
client.run("install . -s build_type=Release")
client.run("install . -s build_type=Debug")
client.run_command('cmake . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake')
client.run_command("cmake --build . --config Debug")
client.run_command(r".\Debug\example.exe")
assert "sayhellobye: Debug!" in client.out
assert "sayhello: Debug!" in client.out
assert "hello: Debug!" in client.out
assert "bye: Debug!" in client.out
client.run_command("cmake --build . --config Release")
client.run_command(r".\Release\example.exe")
assert "sayhellobye: Release!" in client.out
assert "sayhello: Release!" in client.out
assert "hello: Release!" in client.out
assert "bye: Release!" in client.out


@pytest.mark.tool("cmake")
def test_custom_names(setup_client_with_greetings):
Expand Down Expand Up @@ -582,32 +560,6 @@ def requirements(self):
settings = "build_type"
""")

def test_component_not_found(self):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was indented inside another test!!! Never called.
It was duplicated in a merge, it exists above, so not losing a test.

conanfile = textwrap.dedent("""
from conan import ConanFile
class GreetingsConan(ConanFile):
def package_info(self):
self.cpp_info.components["hello"].libs = ["hello"]
self.cpp_info.components["hello"].libdirs = ["lib"]
self.cpp_info.components["hello"].includedirs = ["include"]
""")
client = TestClient()
client.save({"conanfile.py": conanfile})
client.run("create . --name=greetings --version=0.0.1")

conanfile = textwrap.dedent("""
from conan import ConanFile
class WorldConan(ConanFile):
requires = "greetings/0.0.1"
def package_info(self):
self.cpp_info.components["helloworld"].requires = ["greetings::non-existent"]
""")
client.save({"conanfile.py": conanfile})
client.run("create . --name=world --version=0.0.1")
client.run("install --requires=world/0.0.1@ -g CMakeDeps", assert_error=True)
assert ("Component 'greetings::non-existent' not found in 'greetings' "
"package requirement" in client.out)

client = TestClient()
client.save({"zlib.py": zlib, "mypkg.py": mypkg, "final.py": final, "consumer.py": consumer})
client.run("create zlib.py")
Expand Down Expand Up @@ -820,7 +772,7 @@ def build(self):
""")
if check_components_exist is False:
conanfile = conanfile.format("deps.check_components_exist=False")
elif check_components_exist is True:
elif check_components_exist:
conanfile = conanfile.format("deps.check_components_exist=True")
else:
conanfile = conanfile.format("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ def test_reuse_with_modules_and_config(client):


@pytest.mark.tool("cmake")
@pytest.mark.parametrize("find_mode_PKGA, find_mode_PKGB, find_mode_consumer", find_modes)
def test_transitive_modules_found(find_mode_PKGA, find_mode_PKGB, find_mode_consumer):
@pytest.mark.parametrize("find_mode_pkga, find_mode_pkgb, find_mode_consumer", find_modes)
def test_transitive_modules_found(find_mode_pkga, find_mode_pkgb, find_mode_consumer):
"""
related to https://github.com/conan-io/conan/issues/10224
modules files variables were set with the pkg_name_FOUND or pkg_name_VERSION
Expand Down Expand Up @@ -187,8 +187,8 @@ def build(self):
""")

client.save({"pkgb.py": conan_pkg.format(requires='requires="pkga/1.0"', filename='MYPKGB', module_filename='MYPKGB',
mode=find_mode_PKGB),
"pkga.py": conan_pkg.format(requires='', filename='MYPKGA', module_filename='unicorns', mode=find_mode_PKGA),
mode=find_mode_pkgb),
"pkga.py": conan_pkg.format(requires='', filename='MYPKGA', module_filename='unicorns', mode=find_mode_pkga),
"consumer.py": consumer,
"CMakeLists.txt": cmakelist.format(find_mode=find_mode_consumer)})

Expand All @@ -210,6 +210,6 @@ def build(self):
assert "MYPKGB_DEFINITIONS: -DDEFINE_MYPKGB" in client.out
assert "Conan: Target declared 'pkga::pkga'"

if find_mode_PKGA == "module":
if find_mode_pkga == "module":
assert 'Found unicorns: 1.0 (found version "1.0")' in client.out

Original file line number Diff line number Diff line change
Expand Up @@ -1529,7 +1529,6 @@ def package_info(self):
assert "dep/0.1 cpp_info incorrect .type shared-library for .exe myexe" in c.out



def test_multiple_find_package_subfolder():
c = TestClient()
conanfile = textwrap.dedent("""
Expand Down Expand Up @@ -1575,3 +1574,32 @@ def build(self):
assert "find_package(matrix)" in c.out
assert "target_link_libraries(... matrix::matrix)" in c.out
assert "Conan: Target declared imported INTERFACE library 'matrix::matrix'" in c.out


@pytest.mark.tool("cmake", "3.27")
def test_find_package_casing():
cmakelists = textwrap.dedent("""
cmake_minimum_required(VERSION 3.15)
project(test NONE)

# As long as the package generates hello-config.cmake lowercase, it works
find_package(HellO REQUIRED) # Casing!!!!!
""")
consumer = textwrap.dedent("""
from conan import ConanFile
from conan.tools.cmake import CMake
class Pkg(ConanFile):
requires = "hello/1.0"
generators = "CMakeToolchain", "CMakeDeps"
settings = "os", "compiler", "build_type", "arch"
def build(self):
cmake = CMake(self)
cmake.configure()
""")
client = TestClient()
client.save({"conanfile.py": GenConanfile("hello", "1.0")})
client.run(f"create .")

client.save({"conanfile.py": consumer, "CMakeLists.txt": cmakelists})
client.run(f"build . -c tools.cmake.cmakedeps:new={new_value}")
assert "Conan: Configuring Targets for hello/1.0" in client.out
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_no_soname_flag(nosoname_property):

# If `nosoname_property` is False, and we have a library without the SONAME flag,
# then it should fail
if nosoname_property is False:
if not nosoname_property:
client.run_command(command, assert_error=True)
assert "libnosoname.so: cannot open shared object file: " \
"No such file or directory" in client.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import textwrap
import pytest

from conan.test.assets.genconanfile import GenConanfile
from conan.test.utils.tools import TestClient
new_value = "will_break_next"

Expand Down Expand Up @@ -34,7 +33,6 @@ def package_info(self):
message(STATUS "FOO=${FOO}")
""")


conanfile = textwrap.dedent(f"""
from conan import ConanFile
from conan.tools.cmake import CMake
Expand All @@ -54,4 +52,3 @@ def build(self):
"""-c tools.cmake.cmaketoolchain:extra_variables="{'FOO': '9'}" """)

assert "-- FOO=9" in client.out

12 changes: 6 additions & 6 deletions test/functional/toolchains/cmake/test_cmake_toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,11 +760,11 @@ def package(self):
""")

client.save({"conanfile.py": conanfile,
"libfoo.so": "",
"foobin": "",
"host_profile": host_profile,
"build_profile": build_profile
})
"libfoo.so": "",
"foobin": "",
"host_profile": host_profile,
"build_profile": build_profile
})

client.run("create . -pr:b build_profile -pr:h build_profile")
build_context_package_folder = re.search(r"Package folder ([\w\W]+).conan2([\w\W]+)", str(client.out)).group(2).strip()
Expand Down Expand Up @@ -1345,7 +1345,7 @@ def build(self):

c.save({"android": android,
"conanfile.py": conanfile,
"CMakeLists.txt": cmake,})
"CMakeLists.txt": cmake})
# first run works ok
c.run('build . --profile:host=android')
assert 'sdk: 1.0.0' in c.out
Expand Down
3 changes: 1 addition & 2 deletions test/functional/toolchains/cmake/test_ninja.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ def package(self):
@pytest.mark.parametrize("build_type,shared", [("Release", False), ("Debug", True)])
@pytest.mark.tool("ninja")
def test_locally_build_linux(build_type, shared, client):
settings = "-s os=Linux -s arch=x86_64 -s build_type={} -o hello/*:shared={}".format(build_type,
shared)
settings = f"-s os=Linux -s arch=x86_64 -s build_type={build_type} -o hello/*:shared={shared}"
client.run("install . {}".format(settings))
client.run_command('cmake . -G "Ninja" -DCMAKE_TOOLCHAIN_FILE={} -DCMAKE_BUILD_TYPE={}'
.format(CMakeToolchain.filename, build_type))
Expand Down
Empty file.
28 changes: 28 additions & 0 deletions test/unittests/tools/env/test_env_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,31 @@ def test_relative_paths():
shell=True).communicate()
out = result.decode()
assert 'Hello MyWorld!!!' in out


@pytest.mark.parametrize("values, expected",
[("myscripts", '"$script_folder/myscripts"'),
("/path/myscripts", '"/path/myscripts"'),
("../myscripts", '"$script_folder/../myscripts"'),
("../my scripts", '"$script_folder/../my scripts"'),
(["../my scripts", "path/other"],
'"$script_folder/../my scripts:$script_folder/path/other"')])
def test_relativize(values, expected):
folder = os.path.join(temp_folder(), "subfolder")
os.makedirs(folder)
if isinstance(values, str):
value = os.path.join(folder, values) if not os.path.isabs(values) else values
else:
value = [os.path.join(folder, v) for v in values]
myenv = Environment()
myenv.define_path("PATH", value)
myenv.prepend_path("OTHER", value)
conanfile = ConanFileMock()
conanfile.folders._base_generators = folder
myenv = myenv.vars(conanfile)
with chdir(folder):
myenv.save_sh("test.sh")
content = load("test.sh")
content = content.replace("\\", "/")
assert f'export PATH={expected}' in content
assert f'export OTHER="{expected}:$OTHER"'
Loading