srctree

Robin Linden parent 86c76f6a d56fb98c
etest: Drop no-longer-needed std::source_location-workaround

This was only used for Clang 15 and older.
css/parser_test.cpp added: 63, removed: 116, total 0
@@ -9,7 +9,6 @@
#include "css/property_id.h"
#include "css/rule.h"
 
#include "etest/cxx_compat.h"
#include "etest/etest.h"
 
#include <fmt/core.h>
@@ -19,6 +18,7 @@
#include <cstddef>
#include <iterator>
#include <map>
#include <source_location>
#include <string>
#include <string_view>
#include <tuple>
@@ -79,7 +79,7 @@ bool check_initial_font_values(std::map<css::PropertyId, std::string> const &dec
 
template<class KeyT, class ValueT>
ValueT get_and_erase(
std::map<KeyT, ValueT> &map, KeyT key, etest::source_location const &loc = etest::source_location::current()) {
std::map<KeyT, ValueT> &map, KeyT key, std::source_location const &loc = std::source_location::current()) {
require(map.contains(key), {}, loc);
ValueT value = map.at(key);
map.erase(key);
 
css2/tokenizer_test.cpp added: 63, removed: 116, total 0
@@ -7,9 +7,9 @@
 
#include "css2/token.h"
 
#include "etest/cxx_compat.h"
#include "etest/etest.h"
 
#include <source_location>
#include <string>
#include <string_view>
#include <utility>
@@ -35,10 +35,10 @@ public:
 
std::vector<Token> tokens;
std::vector<ParseError> errors;
etest::source_location loc;
std::source_location loc;
};
 
TokenizerOutput run_tokenizer(std::string_view input, etest::source_location loc = etest::source_location::current()) {
TokenizerOutput run_tokenizer(std::string_view input, std::source_location loc = std::source_location::current()) {
std::vector<Token> tokens;
std::vector<ParseError> errors;
Tokenizer{input,
@@ -50,16 +50,15 @@ TokenizerOutput run_tokenizer(std::string_view input, etest::source_location loc
return {std::move(tokens), std::move(errors), std::move(loc)};
}
 
void expect_token(TokenizerOutput &output,
Token const &t,
etest::source_location const &loc = etest::source_location::current()) {
void expect_token(
TokenizerOutput &output, Token const &t, std::source_location const &loc = std::source_location::current()) {
require(!output.tokens.empty(), "Unexpected end of token list", loc);
expect_eq(output.tokens.front(), t, {}, loc);
output.tokens.erase(begin(output.tokens));
}
 
void expect_error(
TokenizerOutput &output, ParseError e, etest::source_location const &loc = etest::source_location::current()) {
TokenizerOutput &output, ParseError e, std::source_location const &loc = std::source_location::current()) {
require(!output.errors.empty(), "Unexpected end of error list", loc);
expect_eq(output.errors.front(), e, {}, loc);
output.errors.erase(begin(output.errors));
 
ev/null added: 63, removed: 116, total 0
@@ -1,49 +0,0 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#ifndef ETEST_CXX_COMPAT_H_
#define ETEST_CXX_COMPAT_H_
 
#include <version>
 
// Clang 15 has the feature, but reports the wrong file and row, making it less than useful.
#if defined(__cpp_lib_source_location) && (__cpp_lib_source_location >= 201907L) \
&& !(defined(__clang_major__) && (__clang_major__ == 15))
 
#include <source_location>
namespace etest {
using source_location = std::source_location;
} // namespace etest
 
#else
 
#include <cstdint>
namespace etest {
// https://en.cppreference.com/w/cpp/utility/source_location
// NOLINTNEXTLINE(readability-identifier-naming)
class source_location {
public:
static constexpr source_location current(std::uint_least32_t line = __builtin_LINE(),
std::uint_least32_t column = __builtin_COLUMN(),
char const *file_name = __builtin_FILE()) noexcept {
return {line, column, file_name};
}
constexpr std::uint_least32_t line() const noexcept { return line_; }
constexpr std::uint_least32_t column() const noexcept { return column_; }
constexpr char const *file_name() const noexcept { return file_name_; }
constexpr char const *function_name() const noexcept { return ""; }
 
private:
std::uint_least32_t line_{};
std::uint_least32_t column_{};
char const *file_name_{};
 
constexpr source_location(std::uint_least32_t line, std::uint_least32_t column, char const *file_name) noexcept
: line_{line}, column_(column), file_name_{file_name} {}
};
} // namespace etest
 
#endif
 
#endif
 
etest/etest.cpp added: 63, removed: 116, total 0
@@ -4,12 +4,12 @@
 
#include "etest/etest.h"
 
#include "etest/cxx_compat.h"
#include "etest/etest2.h"
 
#include <cassert>
#include <functional>
#include <optional>
#include <source_location>
#include <string>
#include <string_view>
#include <utility>
@@ -42,12 +42,12 @@ void disabled_test(std::string name, std::function<void()> body) noexcept {
});
}
 
void expect(bool b, std::optional<std::string_view> log_message, etest::source_location const &loc) noexcept {
void expect(bool b, std::optional<std::string_view> log_message, std::source_location const &loc) noexcept {
assert(current_actions.has_value());
current_actions.value().get().expect(b, std::move(log_message), loc);
}
 
void require(bool b, std::optional<std::string_view> log_message, etest::source_location const &loc) {
void require(bool b, std::optional<std::string_view> log_message, std::source_location const &loc) {
assert(current_actions.has_value());
current_actions.value().get().require(b, std::move(log_message), loc);
}
 
etest/etest.h added: 63, removed: 116, total 0
@@ -1,15 +1,15 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#ifndef ETEST_TEST_H_
#define ETEST_TEST_H_
 
#include "etest/cxx_compat.h"
#include "etest/etest2.h"
 
#include <functional>
#include <optional>
#include <source_location>
#include <sstream>
#include <string>
#include <string_view>
@@ -25,19 +25,19 @@ void disabled_test(std::string name, std::function<void()> body) noexcept;
// Weak test requirement. Allows the test to continue even if the check fails.
void expect(bool,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) noexcept;
std::source_location const &loc = std::source_location::current()) noexcept;
 
// Hard test requirement. Stops the test (using an exception) if the check fails.
void require(bool,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current());
std::source_location const &loc = std::source_location::current());
 
// Weak test requirement. Prints the types compared on failure (if printable).
template<Printable T, Printable U>
void expect_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) noexcept {
std::source_location const &loc = std::source_location::current()) noexcept {
if (a == b) {
return;
}
@@ -51,7 +51,7 @@ template<typename T, typename U>
void expect_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) noexcept {
std::source_location const &loc = std::source_location::current()) noexcept {
expect(a == b, std::move(log_message), loc);
}
 
@@ -60,7 +60,7 @@ template<Printable T, Printable U>
void require_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
if (a == b) {
return;
}
@@ -74,7 +74,7 @@ template<typename T, typename U>
void require_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
require(a == b, std::move(log_message), loc);
}
 
 
etest/etest2.cpp added: 63, removed: 116, total 0
@@ -4,14 +4,13 @@
 
#include "etest/etest2.h"
 
#include "etest/cxx_compat.h"
 
#include <algorithm>
#include <exception>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <optional>
#include <source_location>
#include <sstream>
#include <string_view>
#include <utility>
@@ -32,7 +31,7 @@ struct TestFailure : public std::exception {};
struct Actions : public IActions {
// Weak test requirement. Allows the test to continue even if the check fails.
void expect(
bool b, std::optional<std::string_view> log_message, etest::source_location const &loc) noexcept override {
bool b, std::optional<std::string_view> log_message, std::source_location const &loc) noexcept override {
if (b) {
return;
}
@@ -46,7 +45,7 @@ struct Actions : public IActions {
}
 
// Hard test requirement. Stops the test (using an exception) if the check fails.
void require(bool b, std::optional<std::string_view> log_message, etest::source_location const &loc) override {
void require(bool b, std::optional<std::string_view> log_message, std::source_location const &loc) override {
if (b) {
return;
}
 
etest/etest2.h added: 63, removed: 116, total 0
@@ -1,16 +1,15 @@
// SPDX-FileCopyrightText: 2021-2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#ifndef ETEST_ETEST2_H_
#define ETEST_ETEST2_H_
 
#include "etest/cxx_compat.h"
 
#include <concepts>
#include <functional>
#include <iosfwd>
#include <optional>
#include <source_location>
#include <sstream>
#include <string>
#include <string_view>
@@ -37,19 +36,19 @@ public:
// Weak test requirement. Allows the test to continue even if the check fails.
virtual void expect(bool,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) noexcept = 0;
std::source_location const &loc = std::source_location::current()) noexcept = 0;
 
// Hard test requirement. Stops the test (using an exception) if the check fails.
virtual void require(bool,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) = 0;
std::source_location const &loc = std::source_location::current()) = 0;
 
// Weak test requirement. Prints the types compared on failure (if printable).
template<Printable T, Printable U>
void expect_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) noexcept {
std::source_location const &loc = std::source_location::current()) noexcept {
if (a == b) {
return;
}
@@ -63,7 +62,7 @@ public:
void expect_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) noexcept {
std::source_location const &loc = std::source_location::current()) noexcept {
expect(a == b, std::move(log_message), loc);
}
 
@@ -72,7 +71,7 @@ public:
void require_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
if (a == b) {
return;
}
@@ -86,7 +85,7 @@ public:
void require_eq(T const &a,
U const &b,
std::optional<std::string_view> log_message = std::nullopt,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
require(a == b, std::move(log_message), loc);
}
};
 
html2/tokenizer_test.cpp added: 63, removed: 116, total 0
@@ -6,12 +6,12 @@
 
#include "html2/token.h"
 
#include "etest/cxx_compat.h"
#include "etest/etest.h"
 
#include <array>
#include <iterator>
#include <optional>
#include <source_location>
#include <string>
#include <string_view>
#include <utility>
@@ -47,7 +47,7 @@ public:
 
std::vector<Token> tokens;
std::vector<ParseErrorWithLocation> errors;
etest::source_location loc;
std::source_location loc;
};
 
struct Options {
@@ -57,7 +57,7 @@ struct Options {
 
TokenizerOutput run_tokenizer(std::string_view input,
Options const &opts = Options{},
etest::source_location loc = etest::source_location::current()) {
std::source_location loc = std::source_location::current()) {
std::vector<Token> tokens;
std::vector<ParseErrorWithLocation> errors;
Tokenizer tokenizer{input,
@@ -85,9 +85,8 @@ TokenizerOutput run_tokenizer(std::string_view input,
return {std::move(tokens), std::move(errors), std::move(loc)};
}
 
void expect_token(TokenizerOutput &output,
Token const &t,
etest::source_location const &loc = etest::source_location::current()) {
void expect_token(
TokenizerOutput &output, Token const &t, std::source_location const &loc = std::source_location::current()) {
require(!output.tokens.empty(), "Unexpected end of token list", loc);
expect_eq(output.tokens.front(), t, {}, loc);
output.tokens.erase(begin(output.tokens));
@@ -95,14 +94,14 @@ void expect_token(TokenizerOutput &output,
 
void expect_text(TokenizerOutput &output,
std::string_view text,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
for (auto c : text) {
expect_token(output, CharacterToken{c}, loc);
}
}
 
void expect_error(
TokenizerOutput &output, ParseError e, etest::source_location const &loc = etest::source_location::current()) {
TokenizerOutput &output, ParseError e, std::source_location const &loc = std::source_location::current()) {
require(!output.errors.empty(), "Unexpected end of error list", loc);
expect_eq(output.errors.front().error, e, {}, loc);
output.errors.erase(begin(output.errors));
@@ -110,7 +109,7 @@ void expect_error(
 
void expect_error(TokenizerOutput &output,
ParseErrorWithLocation const &e,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
require(!output.errors.empty(), "Unexpected end of error list", loc);
expect_eq(output.errors.front(), e, {}, loc);
output.errors.erase(begin(output.errors));
 
js/tokenizer_test.cpp added: 63, removed: 116, total 0
@@ -1,13 +1,13 @@
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#include "js/tokenizer.h"
 
#include "etest/cxx_compat.h"
#include "etest/etest.h"
 
#include <optional>
#include <source_location>
#include <string_view>
#include <vector>
 
@@ -17,7 +17,7 @@ namespace {
 
void expect_tokens(std::string_view input,
std::vector<Token> tokens,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
tokens.push_back(Eof{});
etest::expect_eq(tokenize(input), tokens, std::nullopt, loc);
}
 
layout/layout_property_test.cpp added: 63, removed: 116, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -6,13 +6,13 @@
 
#include "css/property_id.h"
#include "dom/dom.h"
#include "etest/cxx_compat.h"
#include "etest/etest.h"
#include "gfx/color.h"
#include "layout/unresolved_value.h"
#include "style/styled_node.h"
 
#include <optional>
#include <source_location>
#include <string>
#include <utility>
#include <vector>
@@ -25,7 +25,7 @@ template<css::PropertyId IdT>
void expect_property_eq(std::optional<std::string> value,
auto expected,
std::vector<std::pair<css::PropertyId, std::string>> extra_properties = {},
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
dom::Node dom_node = dom::Element{"dummy"s};
style::StyledNode styled_node{
.node = dom_node,
 
style/styled_node_test.cpp added: 63, removed: 116, total 0
@@ -6,11 +6,11 @@
 
#include "css/property_id.h"
#include "dom/dom.h"
#include "etest/cxx_compat.h"
#include "etest/etest.h"
#include "gfx/color.h"
 
#include <optional>
#include <source_location>
#include <string>
#include <string_view>
#include <tuple>
@@ -24,7 +24,7 @@ using etest::expect_eq;
namespace {
template<css::PropertyId IdT>
void expect_property_eq(
std::string value, auto expected, etest::source_location const &loc = etest::source_location::current()) {
std::string value, auto expected, std::source_location const &loc = std::source_location::current()) {
dom::Node dom_node = dom::Element{"dummy"s};
style::StyledNode styled_node{
.node = dom_node,
@@ -39,7 +39,7 @@ template<css::PropertyId IdT>
void expect_relative_property_eq(std::string value,
std::string parent_value,
auto expected,
etest::source_location const &loc = etest::source_location::current()) {
std::source_location const &loc = std::source_location::current()) {
dom::Node dom_node = dom::Element{"dummy"s};
style::StyledNode styled_node{
.node = dom_node,
 
wasm/leb128_test.cpp added: 63, removed: 116, total 0
@@ -1,10 +1,9 @@
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#include "wasm/leb128.h"
 
#include "etest/cxx_compat.h"
#include "etest/etest.h"
 
#include <tl/expected.hpp>
@@ -12,6 +11,7 @@
#include <cstdint>
#include <limits>
#include <optional>
#include <source_location>
#include <sstream>
#include <string>
#include <utility>
@@ -23,13 +23,13 @@ using wasm::Leb128ParseError;
 
namespace {
template<typename T>
void expect_decoded(std::string bytes, T expected, etest::source_location loc = etest::source_location::current()) {
void expect_decoded(std::string bytes, T expected, std::source_location loc = std::source_location::current()) {
expect_eq(Leb128<T>::decode_from(std::stringstream{std::move(bytes)}), expected, std::nullopt, std::move(loc));
};
 
template<typename T>
void expect_decode_failure(
std::string bytes, Leb128ParseError error, etest::source_location loc = etest::source_location::current()) {
std::string bytes, Leb128ParseError error, std::source_location loc = std::source_location::current()) {
expect_eq(Leb128<T>::decode_from(std::stringstream{std::move(bytes)}),
tl::unexpected{error},
std::nullopt,