Skip to content

Commit

Permalink
adapt new tests to test refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
juansblanco committed Nov 8, 2023
1 parent c5645d3 commit e4d5f9a
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions tests/test_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,32 +614,31 @@ def test_msvc_x86(self, capfd, basic_cmake_project):


class TestCMakeDepsGenerators:
@pytest.fixture(scope="class", autouse=True)
def conanfile_py_setup(self):
os.remove("conanfile.txt")
yield

# CMakeDeps generator is declared in the generate() function in conanfile.py
def test_one_generator(self, capfd, chdir_build):
src_dir = Path(__file__).parent.parent
shutil.copy2(src_dir / 'tests' / 'resources' / 'change_generators' / 'single_generator' / 'conanfile.py', "..")
run('cmake .. --fresh -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCMAKE_BUILD_TYPE=Release')
def test_one_generator(self, capfd, basic_cmake_project):
source_dir, binary_dir = change_conanfile(basic_cmake_project, 'single_generator')
run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release')
out, _ = capfd.readouterr()
assert 'Generating done' in out

# CMakeDeps generator is declared both in generators attribute and generate() function in conanfile.py
def test_duplicate_generator(self, capfd, chdir_build):
src_dir = Path(__file__).parent.parent
shutil.copy2(src_dir / 'tests' / 'resources' / 'change_generators' / 'duplicate_generator' / 'conanfile.py', "..")
run('cmake .. --fresh -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCMAKE_BUILD_TYPE=Release', check=False)
def test_duplicate_generator(self, capfd, basic_cmake_project):
source_dir, binary_dir = change_conanfile(basic_cmake_project, 'duplicate_generator')
run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release', check=False)
_, err = capfd.readouterr()
assert ('ConanException: CMakeDeps is declared in the generators attribute, but was instantiated in the '
'generate() method too') in err

# CMakeDeps generator is not declared in either place
def test_no_generator(self, capfd, chdir_build):
src_dir = Path(__file__).parent.parent
shutil.copy2(src_dir / 'tests' / 'resources' / 'change_generators' / 'no_generator' / 'conanfile.py', "..")
run('cmake .. --fresh -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES=conan_provider.cmake -DCMAKE_BUILD_TYPE=Release', check=False)
def test_no_generator(self, capfd, basic_cmake_project):
source_dir, binary_dir = change_conanfile(basic_cmake_project, 'no_generator')
run(f'cmake -S {source_dir} -B {binary_dir} -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES={conan_provider} -DCMAKE_BUILD_TYPE=Release', check=False)
out, _ = capfd.readouterr()
assert 'Could NOT find hello (missing: hello_DIR)' in out

def change_conanfile(basic_cmake_project, gen_resource):
source_dir, binary_dir = basic_cmake_project
os.chdir(source_dir.as_posix())
os.remove("conanfile.txt")
shutil.copy2(src_dir / 'tests' / 'resources' / 'change_generators' / gen_resource / 'conanfile.py', source_dir)
return source_dir, binary_dir

0 comments on commit e4d5f9a

Please sign in to comment.