srctree

Robin Linden parent 774c22ce 317c3235
etest: Port failure tests to the new cc_xfail_test rule

etest/BUILD added: 27, removed: 32, total 0
@@ -1,4 +1,5 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//bzl:defs.bzl", "cc_xfail_test")
 
cc_library(
name = "etest",
@@ -15,4 +16,14 @@ cc_library(
size = "small",
srcs = [src],
deps = [":etest"],
) for src in glob(["*_test.cpp"])]
) for src in glob(
include = ["*_test.cpp"],
exclude = ["*_failure_test.cpp"],
)]
 
[cc_xfail_test(
name = src[:-4],
size = "small",
srcs = [src],
deps = [":etest"],
) for src in glob(["*_failure_test.cpp"])]
 
etest/expect_eq_failure_test.cpp added: 27, removed: 32, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2022 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -6,7 +6,5 @@
 
int main() {
etest::test("this should fail", [] { etest::expect_eq(1, 2); });
 
// Invert to return success on failure.
return !etest::run_all_tests();
return etest::run_all_tests();
}
 
etest/expect_failure_test.cpp added: 27, removed: 32, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2022 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -8,7 +8,5 @@ using etest::expect;
 
int main() {
etest::test("this should fail", [] { expect(false); });
 
// Invert to return success on failure.
return !etest::run_all_tests();
return etest::run_all_tests();
}
 
etest/require_eq_failure_test.cpp added: 27, removed: 32, total 0
@@ -1,17 +1,10 @@
// SPDX-FileCopyrightText: 2021 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2022 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#include "etest/etest.h"
 
#include <cstdlib>
 
int main() {
etest::test("this should fail", [] {
etest::require_eq(1, 2);
std::exit(1); // Exit w/ failure if this line runs.
});
 
// Invert to return success on failure.
return !etest::run_all_tests();
etest::test("this should fail", [] { etest::require_eq(1, 2); });
return etest::run_all_tests();
}
 
etest/require_failure_test.cpp added: 27, removed: 32, total 0
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2021 Robin Lindén <dev@robinlinden.eu>
// SPDX-FileCopyrightText: 2021-2022 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
@@ -7,11 +7,6 @@
using etest::require;
 
int main() {
etest::test("this should fail", [] {
require(false);
std::exit(1); // Exit w/ failure if this line runs.
});
 
// Invert to return success on failure.
return !etest::run_all_tests();
etest::test("this should fail", [] { require(false); });
return etest::run_all_tests();
}