Currently Inja's CMake config will build unit tests as long as `BUILD_TESTING` is enabled. As a result, when including Inja in another CMake project, it is not possible to build the latter's unit tests without also enabling Inja's own unit tests.
It's common for libraries to include a separate option for controlling its own unit test targets, in addition to observing the global `BUILD_TESTING` option. For instance, nlohmann/json has a `JSON_BuildTests` option: 973c52dd4a/CMakeLists.txt (L18)
Also see https://cliutils.gitlab.io/modern-cmake/chapters/testing.html .
This commit adds a `INJA_BUILD_TESTS` flag to address this.
* resync single_include
* Undo PIMPL pattern in Environment
* Environment now supports copy construction and assignment
* Add test for copying Environment
Closes#126
* apply documentation changes to single_include
* retain scope when including a template
* Use data from current scope when rendering an included template.
This allows included templates to access loop variables, which
was not possible before.
* Add test
* 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
- You can now update the single include file in a meson build by using
the target 'amalg'.
- The meson build also now builds the single include test suite.
- cmake build updated to use the new script to update the single
include.
Commit a5862a0 made the linking step in update_loop_data unecessary
because the loop's copy of the data was made to come from the parent
loop's data rather than the original client's data.
While at it, also add one more nested loop test case.
* Fix for issue #82 - Nested loops
I made the following changes in renderer.hpp
- Removed the member LoopLevel::it - it was not being used and was
causing issues.
- Added LoopLevel::loop_type with a matching enum class to mark the loop
as looping on either a Map or an Array. This was to replace the hard to
understand test for key_name.empty().
- Modified update_loop_data to get the correct data for map type loops
when copying in outer loop control data.
- Modified update_loop_data to only copy in the outer loop data during
StartLoop, it does not need to be done at EndLoop and can be expensive
since it can copy a large part of the json tree.
All the tests pass and the test cases from the issue also now work. Both
GCC and Clang will compile and run the tests with no issue. No issue is
seen with address_sanitizer in either compiler.
* Remove forgotten debugging code.