Skip to content

Commit 1a5647b

Browse files
committed
revert C++ standard to 20 and improve error handling in expression evaluation
1 parent b00c5f3 commit 1a5647b

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ if (CCR_BUILD_TESTS)
3333
ccr_enable_testing()
3434
endif()
3535

36-
set(CMAKE_CXX_STANDARD 23)
36+
set(CMAKE_CXX_STANDARD 20)
3737
set(CMAKE_CXX_STANDARD_REQUIRED On)
3838
set(CMAKE_CXX_EXTENSIONS Off)
3939

cucumber_cpp/library/cucumber_expression/Ast.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <cctype>
33
#include <map>
44
#include <ranges>
5+
#include <stdexcept>
56
#include <string>
67
#include <utility>
78
#include <variant>
@@ -118,7 +119,7 @@ namespace cucumber_cpp::library::cucumber_expression
118119
return "invalid";
119120
}
120121

121-
std::unreachable();
122+
throw std::runtime_error("Invalid token type");
122123
}
123124

124125
std::string Token::SymbolOf(TokenType type)

cucumber_cpp/library/cucumber_expression/Expression.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <optional>
1111
#include <ranges>
1212
#include <regex>
13+
#include <stdexcept>
1314
#include <string>
1415
#include <string_view>
1516
#include <utility>
@@ -75,7 +76,7 @@ namespace cucumber_cpp::library::cucumber_expression
7576
return RewriteExpression(node);
7677
}
7778

78-
std::unreachable();
79+
throw std::runtime_error{ "Invalid node type" };
7980
}
8081

8182
std::string Expression::EscapeRegex(std::string_view text) const

cucumber_cpp/library/cucumber_expression/test/TestExpression.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <format>
1010
#include <functional>
1111
#include <gtest/gtest.h>
12+
#include <iostream>
1213
#include <iterator>
1314
#include <limits>
1415
#include <optional>
@@ -125,9 +126,9 @@ namespace cucumber_cpp::library::cucumber_expression
125126

126127
parameterRegistry.AddParameter("textAndOrNumber", { R"(([A-Z]+)?(?: )?([0-9]+)?)" }, [](MatchRange matches) -> std::any
127128
{
128-
std::println("matches: {}", std::ranges::distance(matches));
129+
std::cout << std::format("matches: {}\n", std::ranges::distance(matches));
129130
for (const auto& match : matches)
130-
std::println("match: {}", match.str());
131+
std::cout << std::format("match: {}\n", match.str());
131132

132133
std::optional<std::string> text{ matches[1].matched ? StringTo<std::string>(matches[1].str()) : std::optional<std::string>{ std::nullopt } };
133134
std::optional<std::int64_t> number{ matches[2].matched ? StringTo<std::int64_t>(matches[2].str()) : std::optional<std::int64_t>{ std::nullopt } };

cucumber_cpp/library/test/TestApplication.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <gmock/gmock.h>
77
#include <gtest/gtest.h>
88
#include <string>
9-
#include <utility>
9+
#include <type_traits>
1010

1111
namespace cucumber_cpp::library
1212
{
@@ -32,39 +32,39 @@ namespace cucumber_cpp::library
3232

3333
const std::array args{ "application" };
3434

35-
RunWithArgs(args, std::to_underlying(CLI::ExitCodes::RequiredError));
35+
RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::RequiredError));
3636
}
3737

3838
TEST_F(TestApplication, RunCommandWithoutArguments)
3939
{
4040

4141
const std::array args{ "application", "run" };
4242

43-
RunWithArgs(args, std::to_underlying(CLI::ExitCodes::RequiredError));
43+
RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::RequiredError));
4444
}
4545

4646
TEST_F(TestApplication, RunCommand)
4747
{
4848

4949
const std::array args{ "application", "run", "--feature", "./", "--report", "console" };
5050

51-
RunWithArgs(args, std::to_underlying(CLI::ExitCodes::Success));
51+
RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::Success));
5252
}
5353

5454
TEST_F(TestApplication, DryRunCommand)
5555
{
5656

5757
const std::array args{ "application", "run", "--feature", "./", "--report", "console", "--dry" };
5858

59-
RunWithArgs(args, std::to_underlying(CLI::ExitCodes::Success));
59+
RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::Success));
6060
}
6161

6262
TEST_F(TestApplication, InvalidArgument)
6363
{
6464

6565
const std::array args{ "application", "run", "--feature", "./", "--report", "console", "--doesntexist" };
6666

67-
RunWithArgs(args, std::to_underlying(CLI::ExitCodes::ExtrasError));
67+
RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::ExtrasError));
6868
}
6969

7070
TEST_F(TestApplication, DryRunFeatureFile)
@@ -79,7 +79,7 @@ namespace cucumber_cpp::library
7979

8080
const std::array args{ "application", "run", "--feature", path.c_str(), "--report", "console", "--dry" };
8181

82-
std::string stdoutString = RunWithArgs(args, std::to_underlying(CLI::ExitCodes::Success));
82+
std::string stdoutString = RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::Success));
8383

8484
EXPECT_THAT(stdoutString, testing::HasSubstr("1/1 passed"));
8585
}
@@ -96,7 +96,7 @@ namespace cucumber_cpp::library
9696

9797
const std::array args{ "application", "run", "--feature", path.c_str(), "--report", "console" };
9898

99-
std::string stdoutString = RunWithArgs(args, std::to_underlying(CLI::ExitCodes::Success));
99+
std::string stdoutString = RunWithArgs(args, static_cast<std::underlying_type_t<CLI::ExitCodes>>(CLI::ExitCodes::Success));
100100

101101
EXPECT_THAT(stdoutString, testing::HasSubstr("1/1 passed"));
102102
}

0 commit comments

Comments
 (0)