Skip to content

Commit 790904f

Browse files
authored
test(generator): make failures more readable (#7019)
Using a `TestWithParam<absl::string_view>` produces very unreadable failures: the string view is printed one character at a time. And we should use `ASSSERT_STATUS_OK()` before using an `StatusOr<T>`.
1 parent 6226d11 commit 790904f

1 file changed

Lines changed: 3 additions & 9 deletions

File tree

generator/integration_tests/generator_integration_test.cc

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include "google/cloud/internal/getenv.h"
1818
#include "google/cloud/status_or.h"
1919
#include "google/cloud/testing_util/status_matchers.h"
20-
#include "absl/strings/string_view.h"
21-
#include "absl/time/clock.h"
22-
#include "absl/time/time.h"
2320
#include "generator/generator.h"
2421
#include "generator/internal/codegen_utils.h"
2522
#include <google/protobuf/compiler/command_line_interface.h>
@@ -32,7 +29,6 @@ namespace cloud {
3229
namespace generator_internal {
3330
namespace {
3431

35-
using ::google::cloud::testing_util::IsOk;
3632
using ::testing::ElementsAreArray;
3733

3834
StatusOr<std::vector<std::string>> ReadFile(std::string const& filepath) {
@@ -48,8 +44,7 @@ StatusOr<std::vector<std::string>> ReadFile(std::string const& filepath) {
4844
return file_contents;
4945
}
5046

51-
class GeneratorIntegrationTest
52-
: public testing::TestWithParam<absl::string_view> {
47+
class GeneratorIntegrationTest : public testing::TestWithParam<std::string> {
5348
protected:
5449
void SetUp() override {
5550
auto run_integration_tests =
@@ -146,12 +141,11 @@ class GeneratorIntegrationTest
146141

147142
TEST_P(GeneratorIntegrationTest, CompareGeneratedToGolden) {
148143
auto golden_file = ReadFile(absl::StrCat(golden_path_, GetParam()));
149-
EXPECT_THAT(golden_file, IsOk());
144+
ASSERT_STATUS_OK(golden_file);
150145
auto generated_file =
151146
ReadFile(absl::StrCat(output_path_, product_path_, GetParam()));
147+
ASSERT_STATUS_OK(generated_file);
152148

153-
EXPECT_THAT(generated_file, IsOk());
154-
EXPECT_EQ(golden_file->size(), generated_file->size());
155149
EXPECT_THAT(*golden_file,
156150
ElementsAreArray(generated_file->begin(), generated_file->end()));
157151
}

0 commit comments

Comments
 (0)