Skip to content

Commit

Permalink
Merge pull request #623 from conan-io/test/subdir
Browse files Browse the repository at this point in the history
new test for subdir
  • Loading branch information
memsharded authored Apr 3, 2024
2 parents f68f4e2 + 3e830e5 commit 82284c0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tests/resources/subdir2/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.24)
project(MyApp CXX)

add_subdirectory(subdir)

2 changes: 2 additions & 0 deletions tests/resources/subdir2/conanfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[requires]
hello/0.1
3 changes: 3 additions & 0 deletions tests/resources/subdir2/subdir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
find_package(hello REQUIRED)
add_executable(appSubdir main.cpp)
target_link_libraries(appSubdir hello::hello)
2 changes: 2 additions & 0 deletions tests/resources/subdir2/subdir/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "hello.h"
int main(){hello();}
21 changes: 21 additions & 0 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,27 @@ def test_add_subdirectory(self, capfd):
out, _ = capfd.readouterr()
assert "subdir/0.1: Hello World Release!" in out


class TestSubdir2:

def test_add_subdirectory(self, tmp_path_factory, capfd):
"The CMAKE_PREFIX_PATH is set for CMakeLists.txt included with add_subdirectory BEFORE the first find_package."
workdir = tmp_path_factory.mktemp("test_subdir")
source_dir, binary_dir = setup_cmake_workdir(workdir, ["subdir2"])

run(f"cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release")
out, _ = capfd.readouterr()
assert "first find_package() found. Installing dependencies with Conan" in out
run(f"cmake --build {binary_dir} --config Release")
if platform.system() == "Windows":
app_executable = binary_dir / "subdir" / "Release" / "appSubdir.exe"
else:
app_executable = binary_dir / "subdir" / "appSubdir"
run(app_executable.as_posix())
out, _ = capfd.readouterr()
assert "hello/0.1: Hello World Release!" in out


class TestLibcxx:
@darwin
def test_libcxx_macos(self, capfd, basic_cmake_project):
Expand Down

0 comments on commit 82284c0

Please sign in to comment.