Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadFileToString fix and not using bools in deno.h #260

Merged
merged 3 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix error handling in deno::ReadFileToString
Starts a unit test for it, and adds to mock_runtime_test.
  • Loading branch information
ry committed Jun 15, 2018
commit e399cfe3ca8c4f11f60f9cdb608df6b5edeee9f8
1 change: 1 addition & 0 deletions deno2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ executable("deno") {
executable("mock_runtime_test") {
testonly = true
sources = [
"file_util_test.cc",
"from_snapshot.cc",
"mock_runtime_test.cc",
]
Expand Down
5 changes: 4 additions & 1 deletion deno2/file_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ namespace deno {

bool ReadFileToString(const char* fn, std::string* contents) {
std::ifstream file(fn, std::ios::binary);
if (file.fail()) {
return false;
}
contents->assign(std::istreambuf_iterator<char>{file}, {});
return !file.bad();
return !file.fail();
}

class StartupDataCppWriter {
Expand Down
13 changes: 13 additions & 0 deletions deno2/file_util_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright 2018 Ryan Dahl <[email protected]>
// All rights reserved. MIT License.
#include "testing/gtest/include/gtest/gtest.h"

#include "file_util.h"

TEST(FileUtilTest, ReadFileToStringFileNotExist) {
std::string output;
EXPECT_FALSE(deno::ReadFileToString("/should_error_out.txt", &output));
}

// TODO(ry) success unit test. Needs a tempfile or fixture.
// TEST(FileUtilTest, ReadFileToStringSuccess) { }