Skip to content

Commit

Permalink
remove ansi color codes from examples
Browse files Browse the repository at this point in the history
Change-Id: Id81901e82391b37914745339ee2c590ff2ea2a88
  • Loading branch information
oliverlee committed Dec 27, 2023
1 parent 9aa83fd commit 4fcbf8b
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 68 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ auto main() -> int
when run, will print

```console:example/minimal_pass.log
test `truthy`...[32m[CONSTEXPR PASS][0m
[32mall tests passed[0m (1 test)
test `truthy`...[CONSTEXPR PASS]
all tests passed (1 test)
```

Expand All @@ -46,10 +46,10 @@ auto main(int argc, char*[]) -> int
will print
```console:example/minimal_fail.log
test `falsy`...[31m[FAIL][0m example/minimal_fail.cpp:9
[31m[2m(0 == 1)[0m
test `falsy`...[FAIL] example/minimal_fail.cpp:9
(0 == 1)
0 tests passed | [31m1 test failed[0m
0 tests passed | 1 test failed
```

Expand Down
69 changes: 56 additions & 13 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//rules:binary_log.bzl", "synchronized_binary_log")

cc_library(
name = "skytest_wrapper",
hdrs = ["skytest.hpp"],
include_prefix = "skytest",
deps = ["//:skytest"],
)

cc_binary(
name = "minimal_pass",
srcs = ["minimal_pass.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

synchronized_binary_log(
Expand All @@ -15,7 +22,7 @@ synchronized_binary_log(
cc_binary(
name = "minimal_fail",
srcs = ["minimal_fail.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

synchronized_binary_log(
Expand All @@ -26,19 +33,19 @@ synchronized_binary_log(
cc_test(
name = "binary_comparisons",
srcs = ["binary_comparisons.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

cc_test(
name = "logical_operations",
srcs = ["logical_operations.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

cc_binary(
name = "additional_output",
srcs = ["additional_output.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

synchronized_binary_log(
Expand All @@ -49,7 +56,7 @@ synchronized_binary_log(
cc_binary(
name = "user_defined_predicates",
srcs = ["user_defined_predicates.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

synchronized_binary_log(
Expand All @@ -61,7 +68,7 @@ cc_binary(
name = "described_predicates_20",
srcs = ["described_predicates_20.cpp"],
copts = ["-std=c++20"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

synchronized_binary_log(
Expand All @@ -72,7 +79,7 @@ synchronized_binary_log(
cc_binary(
name = "described_predicates",
srcs = ["described_predicates.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

synchronized_binary_log(
Expand All @@ -83,24 +90,60 @@ synchronized_binary_log(
cc_test(
name = "type_parameterized",
srcs = ["type_parameterized.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

cc_test(
name = "value_parameterized",
srcs = ["value_parameterized.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

cc_test(
name = "param_ref_parameterized",
srcs = ["param_ref_parameterized.cpp"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

cc_test(
name = "param_parameterized",
srcs = ["param_parameterized.cpp"],
copts = ["-std=c++20"],
deps = ["//:skytest"],
deps = [":skytest_wrapper"],
)

update_targets = [
":minimal_pass_log.update.sh",
":minimal_fail_log.update.sh",
":additional_output_log.update.sh",
":user_defined_predicates_log.update.sh",
":described_predicates_log.update.sh",
":described_predicates_20_log.update.sh",
]

genrule(
name = "update_all_sh",
srcs = update_targets,
outs = ["update_all.sh"],
cmd = """
set -euo pipefail
echo "set -euo pipefail" > $@
echo "" >> $@
echo "for cmd in {update_targets}; do" >> $@
echo " \"\\$$cmd\"" >> $@
echo "done" >> $@
""".format(
update_targets = " ".join([
"$(rootpath {})".format(x)
for x in update_targets
]),
),
tags = ["manual"],
visibility = ["//visibility:private"],
)

sh_binary(
name = "update_all",
srcs = ["update_all.sh"],
data = update_targets,
)
10 changes: 5 additions & 5 deletions example/additional_output.log
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
test `string-view-ish`...[CONSTEXPR FAIL] example/additional_output.cpp:11
(1 == 2)
test `string-view-ish`...[CONSTEXPR FAIL] example/additional_output.cpp:11
(1 == 2)
a message
test `ostream invocable closure`...[CONSTEXPR FAIL] example/additional_output.cpp:16
(std::pair<int, int>{...} == std::pair<int, int>{...})
test `ostream invocable closure`...[CONSTEXPR FAIL] example/additional_output.cpp:16
(std::pair<int, int>{...} == std::pair<int, int>{...})
1, 2

0 tests passed | 2 tests failed
0 tests passed | 2 tests failed
6 changes: 3 additions & 3 deletions example/described_predicates.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test `empty array`...[CONSTEXPR FAIL] example/described_predicates.cpp:24
empty([1, 2, 3])
test `empty array`...[CONSTEXPR FAIL] example/described_predicates.cpp:24
empty([1, 2, 3])

0 tests passed | 1 test failed
0 tests passed | 1 test failed
Binary file modified example/described_predicates_20.log
Binary file not shown.
6 changes: 3 additions & 3 deletions example/minimal_fail.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test `falsy`...[FAIL] example/minimal_fail.cpp:9
(0 == 1)
test `falsy`...[FAIL] example/minimal_fail.cpp:9
(0 == 1)

0 tests passed | 1 test failed
0 tests passed | 1 test failed
4 changes: 2 additions & 2 deletions example/minimal_pass.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test `truthy`...[CONSTEXPR PASS]
all tests passed (1 test)
test `truthy`...[CONSTEXPR PASS]
all tests passed (1 test)
9 changes: 9 additions & 0 deletions example/skytest.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "_virtual_includes/skytest/skytest/skytest.hpp"

#include <iostream>

template <>
const auto ::skytest::cfg<::skytest::override> =
::skytest::runner<>{std::cout, ::skytest::colors{{}, {}, {}, {}}};
6 changes: 3 additions & 3 deletions example/user_defined_predicates.log
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
test `empty array`...[CONSTEXPR FAIL] example/user_defined_predicates.cpp:16
(lambda at example/user_defined_predicates.cpp:12:38){}([1, 2, 3])
test `empty array`...[CONSTEXPR FAIL] example/user_defined_predicates.cpp:16
(lambda at example/user_defined_predicates.cpp:12:38){}([1, 2, 3])

0 tests passed | 1 test failed
0 tests passed | 1 test failed
14 changes: 8 additions & 6 deletions rules/binary_log.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Rule for generating and testing log files for a binary's output
"""

load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@local_config_info//:defs.bzl", "BAZEL_WORKSPACE_ROOT")

def binary_log(
name,
Expand Down Expand Up @@ -72,21 +73,17 @@ def synchronized_binary_log(
set -euo pipefail
echo "set -euo pipefail" > $@
echo "" >> $@
echo "cd \\$${{BUILD_WORKSPACE_DIRECTORY}}" >> $@
echo "cd {workspace_dir}" >> $@
echo "$(execpath {src}) > $(rootpath {log}) || true" >> $@
""".format(
src = src,
log = log,
workspace_dir = BAZEL_WORKSPACE_ROOT,
),
tags = ["manual"],
visibility = ["//visibility:private"],
)

native.sh_binary(
name = name + ".update",
srcs = [name + ".update.sh"],
)

diff_test(
name = name,
file1 = log,
Expand All @@ -95,3 +92,8 @@ echo "$(execpath {src}) > $(rootpath {log}) || true" >> $@
str(label).replace("@//", "//"),
),
)

native.sh_binary(
name = name + ".update",
srcs = [name + ".update.sh"],
)
3 changes: 1 addition & 2 deletions src/cfg.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include "src/default_printer.hpp"
#include "src/runner.hpp"

#include <iostream>
Expand All @@ -12,6 +11,6 @@ struct override

template <class = override>
// NOLINTNEXTLINE(cppcoreguidelines-interfaces-global-init)
const auto cfg = runner<default_printer>{std::cout};
const auto cfg = runner<>{std::cout};

} // namespace skytest
Loading

0 comments on commit 4fcbf8b

Please sign in to comment.