From 5b58506abdceb4d40b08b7a6cd255ff653687b03 Mon Sep 17 00:00:00 2001 From: David Yip Date: Fri, 1 Mar 2019 03:51:12 -0600 Subject: [PATCH] First cut at Conanfile and Conan package test. (#50) --- conanfile.py | 34 ++++++++++++++++++++++++++++++++++ test_package/CMakeLists.txt | 14 ++++++++++++++ test_package/conanfile.py | 25 +++++++++++++++++++++++++ test_package/example.cpp | 15 +++++++++++++++ 4 files changed, 88 insertions(+) create mode 100644 conanfile.py create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/example.cpp diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..a69c8ac --- /dev/null +++ b/conanfile.py @@ -0,0 +1,34 @@ +from conans import ConanFile, CMake, tools + +class ExpectedConan(ConanFile): + name = "expected" + version = "master" + license = "CC0-1.0" + author = "Simon Brand " + url = "https://github.com/TartanLlama/expected" + description = "C++11/14/17 std::expected with functional-style extensions" + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + exports_sources = "*" + + def source(self): + tools.replace_in_file('CMakeLists.txt', 'project(expected)', + '''project(expected) +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + ''') + + def configure_cmake(self): + cmake = CMake(self) + cmake.configure() + return cmake + + def build(self): + cmake = self.configure_cmake() + cmake.build() + + if not tools.cross_building(self.settings): + self.run('%s/bin/tests' % self.build_folder) + + def package(self): + self.copy('*.hpp', dst='include/tl', src='tl') diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..ad6dc6e --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,14 @@ +cmake_minimum_required(VERSION 2.8.12) +project(PackageTest CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(example example.cpp) +target_link_libraries(example ${CONAN_LIBS}) + +# CTest is a testing tool that can be used to test your project. +# enable_testing() +# add_test(NAME example +# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin +# COMMAND example) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..60461ff --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,25 @@ +import os + +from conans import ConanFile, CMake, tools + + +class ExpectedTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + # Current dir is "test_package/build/" and CMakeLists.txt is + # in "test_package" + cmake.configure() + cmake.build() + + def imports(self): + self.copy("*.dll", dst="bin", src="bin") + self.copy("*.dylib*", dst="bin", src="lib") + self.copy('*.so*', dst='bin', src='lib') + + def test(self): + if not tools.cross_building(self.settings): + os.chdir("bin") + self.run(".%sexample" % os.sep) diff --git a/test_package/example.cpp b/test_package/example.cpp new file mode 100644 index 0000000..c727903 --- /dev/null +++ b/test_package/example.cpp @@ -0,0 +1,15 @@ +#include + +tl::expected maybe_do_something(int i) { + if (i < 5) { + return 0; + } else { + return tl::make_unexpected("Uh oh"); + } +} + +int main(int argc, char** argv) { + (void)argv; + + return maybe_do_something(0).value_or(-1); +}