Throw exception if a file cannot be opened, fix travis-ci builds (#117)

* throw exception if a file cannot be opened

* Add a new function in utils.hpp: open_file_or_throw: This function
  returns an opened std::ifstream or throws by calling `inja_throw`.
* Use this function in Parser::load_file which previously returned an
  empty string if the file couldn't be opened.
* Use this function in Environment::load_json which previously threw
  a `nlohmann::detail::parse_error` if the file couldn't be opened.
* In Parser::parse_statement: When including files through `include`,
  do not attempt to (re-)parse templates from files that were already
  included. Additionally, this prevents inja from attempting to load
  in-memory templates by their name from disk.
* Add tests that check if an exception is thrown when attempting to
  open files that do not exist.

* cmake: enable C++11

* cmake: require C++11 when depending on single_inja

* code style
This commit is contained in:
Tom
2019-09-08 15:05:01 +02:00
committed by pantor
parent 57ac9b9372
commit 419c93c840
7 changed files with 48 additions and 9 deletions

View File

@@ -36,7 +36,7 @@ target_include_directories(inja INTERFACE
$<INSTALL_INTERFACE:${INJA_INSTALL_INCLUDE_DIR}>
)
# target_compile_features(inja INTERFACE cxx_std_11)
target_compile_features(inja INTERFACE cxx_std_11)
set(INJA_PACKAGE_USE_EMBEDDED_JSON OFF)
@@ -89,6 +89,7 @@ if(BUILD_TESTING)
add_library(single_inja INTERFACE)
target_compile_features(single_inja INTERFACE cxx_std_11)
target_include_directories(single_inja INTERFACE single_include include third_party/include)
add_executable(single_inja_test