aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrouslan@chromium.org <rouslan@chromium.org@38ededc0-08b8-5190-f2ac-b31f878777ad>2014-07-23 19:52:03 +0000
committerrouslan@chromium.org <rouslan@chromium.org@38ededc0-08b8-5190-f2ac-b31f878777ad>2014-07-23 19:52:03 +0000
commitd75941244491c922456bf0fa4a987c098f082a76 (patch)
treecfca6c61fb69eb22e64409a047e27ca24682c263
parent9df6dae6a50aaed83d010be8a05030c15be204a0 (diff)
downloadsrc-d75941244491c922456bf0fa4a987c098f082a76.tar.gz
A poor man's release-time assert for failing to open the test data file.
This patch prevents running unit tests from an incorrect directory in release mode. Release mode builds ignore assert(file.is_open()) for the test data file, which causes many hard-to-diagnose crashes due to the rest of the code relying on that file being open. See http://crbug.com/395169 and http://crbug.com/396203 for examples. R=roubert@google.com Review URL: https://codereview.appspot.com/116200043 git-svn-id: http://libaddressinput.googlecode.com/svn/trunk@316 38ededc0-08b8-5190-f2ac-b31f878777ad
-rw-r--r--cpp/test/fake_downloader.cc7
1 files changed, 6 insertions, 1 deletions
diff --git a/cpp/test/fake_downloader.cc b/cpp/test/fake_downloader.cc
index ae16b77..c642eac 100644
--- a/cpp/test/fake_downloader.cc
+++ b/cpp/test/fake_downloader.cc
@@ -16,7 +16,9 @@
#include <cassert>
#include <cstddef>
+#include <cstdlib>
#include <fstream>
+#include <iostream>
#include <map>
#include <string>
#include <utility>
@@ -72,7 +74,10 @@ const LookupKeyUtil& GetAggregateLookupKeyUtil() {
std::map<std::string, std::string> InitData() {
std::map<std::string, std::string> data;
std::ifstream file(kDataFileName);
- assert(file.is_open());
+ if (!file.is_open()) {
+ std::cerr << "Error opening \"" << kDataFileName << "\"." << std::endl;
+ std::exit(EXIT_FAILURE);
+ }
std::string line;
while (file.good()) {