Previously a key like:
"a\u0000\u0001b" = 1
Would get written with literal control characters, rather than escapes:
"a<00><01>b" = 1
The "valid/key/quoted-unicode" test from toml-test would fail with this,
although it seems they're not run automatically(?)
Can also reproduce with something like:
% cat test.cpp
#include <toml.hpp>
#include <iostream>
int main()
{
const auto data = toml::parse("test.toml");
std::cout << data << "\n";
return 0;
}
% cat test.toml
"a\u0000\u0001b" = "a\u0000\u0001b"
% c++ -I. test.cpp
% ./a.out
"ab" = "a\u0000\u0001b"
% ./a.out | hexdump -C
00000000 22 61 00 01 62 22 20 3d 20 22 61 5c 75 30 30 30 |"a..b" = "a\u000|
00000010 30 5c 75 30 30 30 31 62 22 0a 0a |0\u0001b"..|
We are using patched libc++ which uses raw pointers for vector itrators
to improve code compilation speed. This commit fixed two compilation
issues in toml11:
* location::const_iterator deinition assumes that vector const_iterator
is struct or class type rather than raw pointer.
* `const const_itetr foo()` triggers `-Wignored-qualifiers` for primitive
types and `void` which breaks `-Wextra -Werror` compilation.
When creating the inner iterator, make sure it points into the same
vector as the outer iterator. Otherwise, attempts to reset the iterator
wind up causing it to read out-of-bounds.
Fixes#199.
- fix error messages that referred to the wrong functions.
- parse_key(): remove "detail::" from the only error message that had
it, for consistency with the other error messages in that function
My recent patch had introduced a conditional use-after-move bug into the
test_parse_function_compiles function. This patch fixes that by
reworking the entire test case into a compile-time check. In my
opinion, we're not loosing anything by not actually executing the code
(the result wasn't looked at anyway) and the code becomes much clearer
by omitting the argument-preparation fluff.
The 'result' class has unwrap() and unwrap_err() member functions
overloaded for const lvalue and rvalue *this to avoid an unnecessarily
copying the to-be unwrapped object of its containing object is going to
be discarded anyway. Alas, the parse() function toml/parser.hpp file
stored the parse result in a local `const` variable so, although the
unwrap call would have been the last use of the object in each case, the
unnecessary copy would still be made. This patch removes the `const`
and adds a std::move() to actually benefit from the already implemented
optimization.
This patch consistently changes the inclusion order for unit test files
to the following:
1. The header of the unit under test (using <> includes).
2. The unit_test.hpp header (using "" includes).
3. Any additional auxiliary test headers (using "" includes and sorted alphabetically).
4. Additional system headers needed for the test (using <> includes and sorted alphabetically).
5. Conditionally included system headers (using <> includes).
Putting the unit under test's header at the very beginning has the
advantage of also testing that the header is self-contained. It also
makes it very quick to tell what unit is tested in this file.
This removes one #define from each unit test file and ensures
consistency between file and module names. This consistency, was not
strictly maintained before. I hope that any discrepancies were
unintentional and that a 1:1 mapping is actually what is desired.
Since the definition is now done at one single place, it would be easy
to apply transformations like removing the 'test_' prefix or replacing
'_' with '-' if this should be desired.
Instead of unconditionally attempting to clone from a fixed location
(GitHub) during the build / test process, honor the following two
configuration variables:
TOML11_LANGSPEC_GIT_REPOSITORY
Can be set to override the URL from which the repository is cloned.
This allows using a local mirror, including file:// URLs for working
offline or reducing network traffic.
TOML11_LANGSPEC_SOURCE_DIR
Can be set to configure the location at which the repository is
expected. If it already exists no download will be attempted. This
allows avoiding the additional git-clone(1) altogether and use an
existing directory as-is. This offers two new possibilities:
(1) The same checkout can be reused for building multiple
configurations (e.g. Debug versus Release) saving a little bit of
time and disk space.
(2) Experimental changes can easily be applied to the local source
tree without having them destroyed by the build process.
In order for this flexible location to work, the unit tests which
attempt to read files from the repository had to be adjusted. They now
honor an environment variable TOMLDIR which can be set to point to an
alternate root directory.
All defaults are set such that the previous behavior is maintained.
Instead of introducing the TOMLDIR environment variable, an alternative
solution would have been to set the WORKING_DIRECTORY of the tests to
the TOML11_LANGSPEC_SOURCE_DIR and leave the relative paths in these
tests hard-coded. Alas, some tests also expect that they can /write/
into the current working directory which isn't desirable if it is
potentially pointing outside the build tree. I personally prefer to
mount the source directory read-only and build in a fast tempfs, so this
would e a problem. To be perfectly honest, I don't quite understand why
these tests need to write to the file system in the first place, though.
It seems to me that refactoring them to serialize to a std::ostrstream
instead of a std::ofstream would not only simplify but also speed up the
unit tests and avoid file system problems. But there might have been a
hidden reason why actually using the real file system was considered
necessary for these tests, so I didn't went ahead with that change yet.
Depending on the CMake and Boost version, the -Werror flags that might
get added to CMAKE_CXX_FLAGS could adversely affect the feature
detection logic, leading to the wrong conclusion that Boost.Test isn't
usable altogether. Performing these checks first and only afterwards
altering CMAKE_CXX_FLAGS avoids this issue.