Skip to content

Commit

Permalink
Build tests using modules...
Browse files Browse the repository at this point in the history
...when both FLUX_BUILD_TESTS and FLUX_BUILD_MODULE CMake options are set.

This is a big change set, but it mostly consists of reordering things so that all #includes come before `import flux`.  In some cases we were testing (or using) things in the `detail` namespace, which are now no longer exported; these are currently just ifdef'd out.
  • Loading branch information
tcbrindle committed Jan 6, 2024
1 parent 8323ebe commit bf38e00
Show file tree
Hide file tree
Showing 70 changed files with 180 additions and 236 deletions.
13 changes: 13 additions & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ if(${FLUX_ENABLE_UBSAN})
target_link_options(test-libflux PRIVATE -fsanitize=undefined)
endif()

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.28.0")
if (${FLUX_BUILD_MODULE})
target_sources(test-libflux PUBLIC
FILE_SET CXX_MODULES
BASE_DIRS ${PROJECT_SOURCE_DIR}/module
FILES ${PROJECT_SOURCE_DIR}/module/flux.cpp
)

target_compile_definitions(test-libflux PRIVATE -DUSE_MODULES)
set_target_properties(test-libflux PROPERTIES CXX_SCAN_FOR_MODULES On)
endif()
endif()

if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.16.0")
target_precompile_headers(test-libflux PRIVATE "catch.hpp")
endif()
Expand Down
9 changes: 6 additions & 3 deletions test/test_adjacent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@

#include "catch.hpp"

#include <flux.hpp>
#include <array>

#include "test_utils.hpp"

#include <array>

#ifndef USE_MODULES
#include <flux.hpp>
#else
import flux;
#endif

namespace {

Expand Down
4 changes: 1 addition & 3 deletions test/test_adjacent_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

#include "catch.hpp"

#include <flux.hpp>
#include <array>

#include "test_utils.hpp"

#include <array>

namespace {

constexpr bool test_adjacent_filter()
Expand Down
4 changes: 1 addition & 3 deletions test/test_adjacent_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

#include "catch.hpp"

#include <flux.hpp>
#include <array>

#include "test_utils.hpp"

#include <array>

namespace {

constexpr bool test_pairwise_map() {
Expand Down
4 changes: 4 additions & 0 deletions test/test_all_any_none.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

#include "catch.hpp"

#ifdef USE_MODULES
import flux;
#else
#include <flux/op/all_any_none.hpp>
#endif

namespace {

Expand Down
2 changes: 0 additions & 2 deletions test/test_apply.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

#include "catch.hpp"

#include <flux.hpp>

#include <array>
#include <algorithm>

Expand Down
6 changes: 2 additions & 4 deletions test/test_array_ptr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@

#include "catch.hpp"

#include <flux.hpp>

#include "test_utils.hpp"

#include <array>
#include <algorithm>
#include <numeric>

#include "test_utils.hpp"

namespace {

struct Base {
Expand Down
7 changes: 2 additions & 5 deletions test/test_bitset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@

#include "catch.hpp"

#include <flux.hpp>
#include <flux/source/bitset.hpp>

#include "test_utils.hpp"

#include <array>
#include <iostream>

#include "test_utils.hpp"

namespace {

constexpr bool test_bitset()
Expand Down
2 changes: 0 additions & 2 deletions test/test_bounds_checked.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

#include "catch.hpp"

#include <flux.hpp>

#include <vector>

#include "test_utils.hpp"
Expand Down
2 changes: 0 additions & 2 deletions test/test_cache_last.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

#include "catch.hpp"

#include <flux.hpp>

#include <array>

#include "test_utils.hpp"
Expand Down
7 changes: 0 additions & 7 deletions test/test_cartesian_product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@

#include "catch.hpp"

#include <flux/op/cartesian_product.hpp>
#include <flux/op/reverse.hpp>
#include <flux/source/iota.hpp>
#include <flux/source/empty.hpp>
#include <flux/source/iota.hpp>
#include <flux/op/for_each.hpp>

#include <array>
#include <iostream>
#include <string_view>
Expand Down
2 changes: 0 additions & 2 deletions test/test_cartesian_product_with.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

#include "catch.hpp"

#include <flux.hpp>

#include <array>

#include "test_utils.hpp"
Expand Down
7 changes: 2 additions & 5 deletions test/test_chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@

#include "catch.hpp"

#include <flux.hpp>
#include <flux/op/write_to.hpp>

#include "test_utils.hpp"

#include <array>
#include <iostream>
#include <vector>

#include "test_utils.hpp"

namespace {

constexpr bool test_chain()
Expand Down
26 changes: 20 additions & 6 deletions test/test_chunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@

#include "catch.hpp"

#include <flux.hpp>

#include "test_utils.hpp"

#include <array>
#include <limits>
#include <list>
#include <sstream>

#include "test_utils.hpp"

namespace {

#ifdef _MSC_VER
Expand All @@ -33,8 +31,24 @@ struct NotBidir : flux::inline_sequence_base<NotBidir<Base>> {
constexpr Base& base() & { return base_; }
constexpr Base const& base() const& { return base_; }

struct flux_sequence_traits : flux::detail::passthrough_traits_base<Base> {
static void dec(...) = delete;
struct flux_sequence_traits {
static constexpr auto first(auto& self) { return flux::first(self.base_); }

static constexpr bool is_last(auto& self, auto const& cur) {
return flux::is_last(self.base_, cur);
}

static constexpr void inc(auto& self, auto& cur) {
flux::inc(self.base_, cur);
}

static constexpr decltype(auto) read_at(auto& self, auto const& cur) {
return flux::read_at(self.base_, cur);
}

static constexpr auto last(auto& self) { return flux::last(self.base_); }

static constexpr auto size(auto& self) { return flux::size(self.base_); }
};
};

Expand Down
6 changes: 2 additions & 4 deletions test/test_chunk_by.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@

#include "catch.hpp"

#include <flux.hpp>

#include "test_utils.hpp"

#include <array>
#include <iostream>

#include "test_utils.hpp"

namespace {

constexpr bool test_chunk_by() {
Expand Down
8 changes: 4 additions & 4 deletions test/test_compare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

#include "catch.hpp"

#include <flux.hpp>
#include <array>

#include "test_utils.hpp"

#include <array>

namespace {

struct Test {
Expand Down Expand Up @@ -77,7 +75,9 @@ constexpr bool test_compare()
// empty sequences are equal
{
// ...but still require the element types to be comparable
static_assert(not std::invocable<flux::detail::compare_fn, flux::detail::empty_sequence<int>, flux::detail::empty_sequence<std::nullptr_t>>);
static_assert(not std::invocable<decltype(flux::compare),
decltype(flux::empty<int>),
decltype(flux::empty<std::nullptr_t>)>);

auto r = flux::compare(flux::empty<int>, flux::empty<int>);
static_assert(std::same_as<decltype(r), std::strong_ordering>);
Expand Down
4 changes: 4 additions & 0 deletions test/test_concepts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

#include "catch.hpp"

#ifdef USE_MODULES
import flux;
#else
#include <flux.hpp>
#endif

namespace {

Expand Down
4 changes: 1 addition & 3 deletions test/test_contains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

#include "catch.hpp"

#include <flux/op/contains.hpp>
#include <array>

#include "test_utils.hpp"

#include <array>

namespace {

struct Test {
Expand Down
4 changes: 0 additions & 4 deletions test/test_count.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@

#include "catch.hpp"

#include <flux/op/count.hpp>
#include <flux/op/take_while.hpp>

#include "test_utils.hpp"


namespace {

struct S {
Expand Down
3 changes: 0 additions & 3 deletions test/test_count_if.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@

#include "catch.hpp"

#include <flux/op/count.hpp>
#include <flux/op/take_while.hpp>

#include "test_utils.hpp"


Expand Down
6 changes: 2 additions & 4 deletions test/test_cursors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

#include "catch.hpp"

#include <flux.hpp>

#include "test_utils.hpp"

#include <array>
#include <sstream>

#include "test_utils.hpp"

namespace {

constexpr bool test_cursors()
Expand Down
6 changes: 2 additions & 4 deletions test/test_cycle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

#include "catch.hpp"

#include <flux.hpp>

#include "test_utils.hpp"

#include <array>
#include <limits>

#include "test_utils.hpp"

namespace {

constexpr bool test_cycle() {
Expand Down
6 changes: 2 additions & 4 deletions test/test_drop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@

#include "catch.hpp"

#include <flux.hpp>

#include "test_utils.hpp"

#include <array>
#include <list>
#include <span>
#include <string>
#include <string_view>
#include <vector>

#include "test_utils.hpp"

namespace {

constexpr bool test_drop() {
Expand Down
4 changes: 1 addition & 3 deletions test/test_drop_while.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

#include "catch.hpp"

#include <flux.hpp>
#include <array>

#include "test_utils.hpp"

#include <array>

namespace {

constexpr bool test_drop_while()
Expand Down
4 changes: 4 additions & 0 deletions test/test_empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@

#include "catch.hpp"

#ifdef USE_MODULES
import flux;
#else
#include <flux/source/empty.hpp>
#endif

namespace {

Expand Down
Loading

0 comments on commit bf38e00

Please sign in to comment.