mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
Fix error handling in deno::ReadFileToString
Starts a unit test for it, and adds to mock_runtime_test.
This commit is contained in:
parent
b2694ecbd8
commit
97923e3d26
3 changed files with 18 additions and 1 deletions
|
@ -17,6 +17,7 @@ executable("deno") {
|
|||
executable("mock_runtime_test") {
|
||||
testonly = true
|
||||
sources = [
|
||||
"file_util_test.cc",
|
||||
"from_snapshot.cc",
|
||||
"mock_runtime_test.cc",
|
||||
]
|
||||
|
|
|
@ -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 {
|
||||
|
|
13
deno2/file_util_test.cc
Normal file
13
deno2/file_util_test.cc
Normal file
|
@ -0,0 +1,13 @@
|
|||
// Copyright 2018 Ryan Dahl <ry@tinyclouds.org>
|
||||
// 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) { }
|
Loading…
Reference in a new issue