Skip to content

Commit

Permalink
TST: add test package depending on a cmake subproject
Browse files Browse the repository at this point in the history
  • Loading branch information
dnicolodi committed Mar 12, 2024
1 parent 2daa991 commit 47de165
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tests/packages/cmake-subproject/cmakesubproject.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: 2024 The meson-python developers
#
# SPDX-License-Identifier: MIT

cdef extern from "cmaketest.hpp":
cdef cppclass Test:
Test(int) except +
int add(int)


def sum(int a, int b):
t = new Test(a)
return t.add(b)
17 changes: 17 additions & 0 deletions tests/packages/cmake-subproject/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2024 The meson-python developers
#
# SPDX-License-Identifier: MIT

project('cmake-subproject', ['c', 'cpp', 'cython'], version: '1')

dep = dependency('cmaketest')

py = import('python').find_installation()

py.extension_module(
'cmakesubproject',
'cmakesubproject.pyx',
dependencies: dep,
override_options: ['cython_language=cpp'],
install: true,
)
7 changes: 7 additions & 0 deletions tests/packages/cmake-subproject/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2021 The meson-python developers
#
# SPDX-License-Identifier: MIT

[build-system]
build-backend = 'mesonpy'
requires = ['meson-python']
9 changes: 9 additions & 0 deletions tests/packages/cmake-subproject/subprojects/cmaketest.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2024 The meson-python developers
#
# SPDX-License-Identifier: MIT

[wrap-file]
method = cmake

[provide]
cmaketest = cmaketest_dep
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2024 The meson-python developers
#
# SPDX-License-Identifier: MIT

cmake_minimum_required(VERSION 3.5)

project(cmaketest)
set(CMAKE_CXX_STANDARD 14)

include_directories(${CMAKE_CURRENT_BINARY_DIR})

add_library(cmaketest SHARED cmaketest.cpp)

include(GenerateExportHeader)
generate_export_header(cmaketest)

install(TARGETS cmaketest)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-FileCopyrightText: 2024 The meson-python developers
//
// SPDX-License-Identifier: MIT

#include "cmaketest.hpp"

Test::Test(int x) {
this->x = x;
}

int Test::add(int y) const {
return x + y;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2024 The meson-python developers
//
// SPDX-License-Identifier: MIT

#pragma once
#include "cmaketest_export.h"

class CMAKETEST_EXPORT Test {
private:
int x;
public:
Test(int x);
int add(int y) const;
};
12 changes: 12 additions & 0 deletions tests/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,15 @@ def test_custom_target_install_dir(package_custom_target_dir, tmp_path):
'package/generated/one.py',
'package/generated/two.py',
}


@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform')
def test_cmake_subproject(wheel_cmake_subproject):
artifact = wheel.wheelfile.WheelFile(wheel_cmake_subproject)
assert wheel_contents(artifact) == {

Check warning on line 370 in tests/test_wheel.py

View check run for this annotation

Codecov / codecov/patch

tests/test_wheel.py#L369-L370

Added lines #L369 - L370 were not covered by tests
'cmake_subproject-1.dist-info/METADATA',
'cmake_subproject-1.dist-info/RECORD',
'cmake_subproject-1.dist-info/WHEEL',
f'.cmake_subproject.mesonpy.libs/libcmaketest{LIB_SUFFIX}',
f'cmakesubproject{EXT_SUFFIX}',
}

0 comments on commit 47de165

Please sign in to comment.