Skip to content

Commit 67d622f

Browse files
committed
Bazel: actually run the zipmerge tests
1 parent 9c1efb9 commit 67d622f

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
BasedOnStyle: Chromium
2+
ColumnLimit: 100
3+
IndentWidth: 2
4+
SortIncludes: false
5+
AllowShortIfStatementsOnASingleLine: WithoutElse
6+
AlwaysBreakBeforeMultilineStrings: false
7+
Standard: c++20

misc/bazel/internal/zipmerge/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ cc_binary(
2020
cc_test(
2121
name = "test",
2222
size = "small",
23+
srcs = ["zipmerge_test.cpp"],
24+
data = glob(["test-files/*"]),
2325
deps = [
2426
":lib",
2527
"@bazel_tools//tools/cpp/runfiles",

misc/bazel/internal/zipmerge/zipmerge_test.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <fstream>
55
#include <sstream>
66
#include <string>
7+
#include <cstring>
78

89
#include <gtest/gtest.h>
910
#include <gmock/gmock.h>
@@ -53,10 +54,7 @@ TEST(Zipmerge, FindEocd) {
5354
EXPECT_EQ(find_eocd(buf, sizeof(buf)), buf + 101);
5455
}
5556

56-
const size_t num_hash_bytes = 128 / 8;
57-
const size_t num_hash_uint64s = 2;
58-
59-
std::string read_file(std::string_view filename) {
57+
std::string read_file(const std::string& filename) {
6058
std::ifstream f(filename, std::ios::binary);
6159
EXPECT_TRUE(f) << "Could not open '" << filename << "' (" << std::strerror(errno) << ")";
6260
if (!f) {
@@ -68,12 +66,12 @@ std::string read_file(std::string_view filename) {
6866
}
6967

7068
std::string get_file(const char* name) {
71-
static auto runfiles = []{
72-
std::string error;
73-
auto ret = Runfiles::CreateForTest(&error);
74-
EXPECT_TRUE(ret) << error;
75-
return ret;
76-
}();
69+
static auto runfiles = [] {
70+
std::string error;
71+
auto ret = Runfiles::CreateForTest(&error);
72+
EXPECT_TRUE(ret) << error;
73+
return ret;
74+
}();
7775
return runfiles->Rlocation("_main/misc/bazel/internal/zipmerge/test-files/"s + name);
7876
}
7977

@@ -90,7 +88,7 @@ template <typename... Args>
9088
const char* zipmerge(Args*... inputs) {
9189
reset();
9290
const char* output = nullptr;
93-
std::vector<const char*> args{"self"};
91+
std::vector<std::string> args{"self"};
9492
std::array<const char*, sizeof...(Args)> flags{{inputs...}};
9593
auto i = 0u;
9694
for (; i < flags.size() && std::string_view{flags[i]}.starts_with("-"); ++i) {
@@ -102,7 +100,10 @@ const char* zipmerge(Args*... inputs) {
102100
for (; i < flags.size(); ++i) {
103101
args.push_back(std::string_view{flags[i]}.starts_with("-") ? flags[i] : get_file(flags[i]));
104102
}
105-
EXPECT_EQ(zipmerge_main(args.size(), args.data()), 0);
103+
std::vector<const char*> argv;
104+
std::transform(args.begin(), args.end(), std::back_inserter(argv),
105+
[](const std::string& s) { return s.c_str(); });
106+
EXPECT_EQ(zipmerge_main(argv.size(), argv.data()), 0);
106107
return output;
107108
}
108109

0 commit comments

Comments
 (0)