Commit f5f1796c authored by Stephen Oberholtzer's avatar Stephen Oberholtzer

When running unit tests, read reference files in text mode

This should put an end to all of the reports of unit test failures on
Windows machines.
parent b1c55030
...@@ -95,7 +95,7 @@ class MockGeneratorContext : public GeneratorContext { ...@@ -95,7 +95,7 @@ class MockGeneratorContext : public GeneratorContext {
string actual_contents; string actual_contents;
GOOGLE_CHECK_OK( GOOGLE_CHECK_OK(
File::GetContents(TestSourceDir() + "/" + physical_filename, File::GetContentsAsText(TestSourceDir() + "/" + physical_filename,
&actual_contents, true)); &actual_contents, true));
EXPECT_TRUE(actual_contents == *expected_contents) EXPECT_TRUE(actual_contents == *expected_contents)
<< physical_filename << physical_filename
......
...@@ -90,7 +90,7 @@ class MockGeneratorContext : public GeneratorContext { ...@@ -90,7 +90,7 @@ class MockGeneratorContext : public GeneratorContext {
string actual_contents; string actual_contents;
GOOGLE_CHECK_OK( GOOGLE_CHECK_OK(
File::GetContents(TestSourceDir() + "/" + physical_filename, File::GetContentsAsText(TestSourceDir() + "/" + physical_filename,
&actual_contents, true)) &actual_contents, true))
<< "Unable to get " << physical_filename; << "Unable to get " << physical_filename;
EXPECT_TRUE(actual_contents == *expected_contents) EXPECT_TRUE(actual_contents == *expected_contents)
......
...@@ -90,12 +90,12 @@ TEST(RubyGeneratorTest, GeneratorTest) { ...@@ -90,12 +90,12 @@ TEST(RubyGeneratorTest, GeneratorTest) {
// Load the generated output and compare to the expected result. // Load the generated output and compare to the expected result.
string output; string output;
GOOGLE_CHECK_OK(File::GetContents( GOOGLE_CHECK_OK(File::GetContentsAsText(
TestTempDir() + "/ruby_generated_code_pb.rb", TestTempDir() + "/ruby_generated_code_pb.rb",
&output, &output,
true)); true));
string expected_output; string expected_output;
GOOGLE_CHECK_OK(File::GetContents( GOOGLE_CHECK_OK(File::GetContentsAsText(
ruby_tests + "/ruby_generated_code_pb.rb", ruby_tests + "/ruby_generated_code_pb.rb",
&expected_output, &expected_output,
true)); true));
......
...@@ -3183,7 +3183,7 @@ TEST(TextFormatMapTest, Sorted) { ...@@ -3183,7 +3183,7 @@ TEST(TextFormatMapTest, Sorted) {
tester.SetMapFieldsViaReflection(&message); tester.SetMapFieldsViaReflection(&message);
string expected_text; string expected_text;
GOOGLE_CHECK_OK(File::GetContents( GOOGLE_CHECK_OK(File::GetContentsAsText(
TestSourceDir() + TestSourceDir() +
"/google/protobuf/" "/google/protobuf/"
"testdata/map_test_data.txt", "testdata/map_test_data.txt",
......
...@@ -69,9 +69,9 @@ bool File::Exists(const string& name) { ...@@ -69,9 +69,9 @@ bool File::Exists(const string& name) {
return access(name.c_str(), F_OK) == 0; return access(name.c_str(), F_OK) == 0;
} }
bool File::ReadFileToString(const string& name, string* output) { bool File::ReadFileToString(const string& name, string* output, bool text_mode) {
char buffer[1024]; char buffer[1024];
FILE* file = fopen(name.c_str(), "rb"); FILE* file = fopen(name.c_str(), text_mode ? "rt" : "rb");
if (file == NULL) return false; if (file == NULL) return false;
while (true) { while (true) {
......
...@@ -50,7 +50,7 @@ class File { ...@@ -50,7 +50,7 @@ class File {
// Read an entire file to a string. Return true if successful, false // Read an entire file to a string. Return true if successful, false
// otherwise. // otherwise.
static bool ReadFileToString(const string& name, string* output); static bool ReadFileToString(const string& name, string* output, bool text_mode = false);
// Same as above, but crash on failure. // Same as above, but crash on failure.
static void ReadFileToStringOrDie(const string& name, string* output); static void ReadFileToStringOrDie(const string& name, string* output);
...@@ -85,6 +85,11 @@ class File { ...@@ -85,6 +85,11 @@ class File {
return ReadFileToString(name, output); return ReadFileToString(name, output);
} }
static bool GetContentsAsText(
const string& name, string* output, bool /*is_default*/) {
return ReadFileToString(name, output, true);
}
static bool SetContents( static bool SetContents(
const string& name, const string& contents, bool /*is_default*/) { const string& name, const string& contents, bool /*is_default*/) {
return WriteStringToFile(contents, name); return WriteStringToFile(contents, name);
......
...@@ -77,7 +77,7 @@ const string kEscapeTestStringEscaped = ...@@ -77,7 +77,7 @@ const string kEscapeTestStringEscaped =
class TextFormatTest : public testing::Test { class TextFormatTest : public testing::Test {
public: public:
static void SetUpTestCase() { static void SetUpTestCase() {
GOOGLE_CHECK_OK(File::GetContents( GOOGLE_CHECK_OK(File::GetContentsAsText(
TestSourceDir() + TestSourceDir() +
"/google/protobuf/" "/google/protobuf/"
"testdata/text_format_unittest_data_oneof_implemented.txt", "testdata/text_format_unittest_data_oneof_implemented.txt",
...@@ -99,7 +99,7 @@ string TextFormatTest::static_proto_debug_string_; ...@@ -99,7 +99,7 @@ string TextFormatTest::static_proto_debug_string_;
class TextFormatExtensionsTest : public testing::Test { class TextFormatExtensionsTest : public testing::Test {
public: public:
static void SetUpTestCase() { static void SetUpTestCase() {
GOOGLE_CHECK_OK(File::GetContents(TestSourceDir() + GOOGLE_CHECK_OK(File::GetContentsAsText(TestSourceDir() +
"/google/protobuf/testdata/" "/google/protobuf/testdata/"
"text_format_unittest_extensions_data.txt", "text_format_unittest_extensions_data.txt",
&static_proto_debug_string_, true)); &static_proto_debug_string_, true));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment