Commit Graph

321 Commits

Author SHA1 Message Date
ToruNiina
5e4eb52f84 fix: add cxx_std to check_cxx_source_compiles
in macos, default version is 98 and it fails to compile boost test.
ci fails in the test branch because of apt timeout, but osx jobs works.
2024-06-11 23:47:49 +09:00
ToruNiina
2466959cf9 chore: avoid false-positive ref life warning 2024-03-20 22:42:00 +09:00
ToruNiina
64cd90637b refactor: move cmake component to where it's used 2024-03-20 22:35:03 +09:00
ToruNiina
db72451bcf test: update test to add rec start val 2024-01-04 20:47:46 +09:00
ToruNiina
da3d5153d1 ci: install language pack to test locale 2023-05-28 23:37:53 +09:00
ToruNiina
af13c2867a test: add test case for serializer with locale 2023-05-28 18:47:06 +09:00
ToruNiina
fd969a679b test: check if a large bin ints are parsed 2023-02-12 19:03:59 +09:00
Moritz Klammler
3f197c3cab Fix use-after-move in test_parse_function_compiles and refactor
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.
2022-09-29 19:22:25 +02:00
Moritz Klammler
e86d7c3cd3 Remove excess blank lines at end of file 2022-09-29 19:02:52 +02:00
Moritz Klammler
10fd14f8b9 Consistent unit test header inclusion order
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.
2022-09-29 19:02:52 +02:00
Moritz Klammler
81c5ba9082 Define BOOST_TEST_MODULE in CMake
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.
2022-09-29 19:02:52 +02:00
Moritz Klammler
d7c04ed5ee Factor redundant test boilerplate out into unit_test.hpp helper 2022-09-29 19:02:52 +02:00
Moritz Klammler
b10348c576 More flexible https://github.com/toml-lang/toml handling
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.
2022-09-29 19:02:52 +02:00
Moritz Klammler
ac949437f8 Avoid false negative Boost.Test detection due to -Werror
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.
2022-09-29 17:59:28 +02:00
Moritz Klammler
fe471bcbe9 Autodetect the best option to use Boost.Test
The conditional inclusion of either the library or the header-only
version of the Boost.Test header wasn't tremendously useful in practice
because the tests/CMakeLists.txt file would unconditionally add compile
definitions to basically fore dynamic linking.

This patch adds feature detection to the tests/CMakeLists.txt file to
determine whether to use dynamic linking, static linking or the
header-only version (in that order of preference, for best performance).

The automatic detection could be overridden if needed by defining the
TOML11_WITH_BOOST_TEST_{HEADER,STATIC,DYNAMIC}
variables on the CMake command line.

While we are at it, instead of having a conditional
#define BOOST_TEST_NO_LIB
in each unit test file, handle this once in the CMakeLists.txt file.
2022-09-29 17:59:28 +02:00
Moritz Klammler
5312b8eb0e Honor UNITTEST_FRAMEWORK_LIBRARY_EXIST in all unit test files
Most unit test files checked UNITTEST_FRAMEWORK_LIBRARY_EXIST and
adapted themselves accordingly to either use the header-only version or
link with the library.  Alas, eight files didn't so the project couldn't
really be tested with the header-only version of that Boost library.

This patch adds the missing pre-processor logic to the files that were
missing it.  The style of using no indentation after the '#' was
followed from the existing unit test files.  Some other files in this
repository do indent their pre-processor logic, though.

Since replicating the conditional in every file is kind of verbose,
tedious and, apparently, easily forgotten, I'm wondering whether
isolating that logic into a tiny little auxiliary header and then
unconditionally including that one in each unit test file would be a
good idea, though.
2022-09-29 17:59:28 +02:00
Lukáš Hrázký
6c2c804eff fix: Improve error handling of ifstream a bit
Set the exceptions mask so that exceptions are thrown when an I/O error
occurs. Also throw the same exception type when the opening fails.
2022-09-08 17:05:15 +02:00
Lukáš Hrázký
bf9c9d620d feat: Add a parse(FILE *) interface
The fstream classes are notorious for their non-existent error handling.

This adds a C-style fILE * IO (fopen(), etc.) alternative interface, so
that if a user needs reliable error handling, they can use that, albeit
more inconvenient, but more robust approach.
2022-09-08 17:05:11 +02:00
ToruNiina
d6efdf7d9e test: check if an exception is thrown by overflow 2022-06-08 00:40:28 +09:00
ToruNiina
1c82c7a1dc fix: move cmake option to toplevel cmakelists 2022-03-16 22:40:42 +09:00
ToruNiina
dde351ea40 feat: add escape sequence of ESC
as an unreleased feature
2022-03-16 22:39:52 +09:00
ToruNiina
02fd8a577b feat: workaround __cplusplus problem on MSVC 2021-12-17 22:29:57 +09:00
ToruNiina
23f6c931e5 test: add valid/invalid datetime cases 2021-12-15 00:51:07 +09:00
ToruNiina
2152c85cd1 test: add test_file_ends_without_lf 2021-12-10 23:46:47 +09:00
Philip Top
e08c579e36 fix a change in the key_value name from upstream merge 2021-11-19 08:43:03 -08:00
Philip Top
6dd44dc672 fix project issue with cmake 2021-11-19 08:41:24 -08:00
ToruNiina
1d0b003312 ci: add a patch to avoid nan comparison 2021-06-30 01:18:42 +09:00
ToruNiina
4adf36d9fd test: update typename in json for toml-test 2021-06-27 18:58:10 +09:00
ToruNiina
7b9a1abdb3 feat: add test_find_or_recursive 2021-05-15 20:51:43 +09:00
ToruNiina
db0d9a024b test: add -Wshadow while compiling tests 2021-05-10 20:49:41 +09:00
ToruNiina
06e8b853ba test: add Wshadow=local 2021-05-04 17:50:14 +09:00
ToruNiina
beb665ba58 test: explicitly specify if comments are preserved 2021-04-27 13:19:55 +09:00
ToruNiina
b51ef5e869 test: explicitly specify the comment preservation 2021-04-27 13:18:39 +09:00
ToruNiina
21ea4a348d test: explicitly specify template arguments
toml::value is an alias of default parameters, so we need to avoid
conflict of definitions between default and non-default parameters
2021-04-27 13:12:37 +09:00
ToruNiina
c4a803df50 test: add comment/no-comment cases to parse_array
When we add a macro to change the default comment preservation scheme,
some of the current tests that assume comments are discarded by defualt
fails. To make it more robust, we need to explicitly specify the comment
preservation scheme and add test cases for both of discard_ and
preserve_comments.
2021-04-27 13:05:03 +09:00
ToruNiina
e658a0126c test: disable macro testing if the macro is diabled 2021-04-02 18:26:24 +09:00
ToruNiina
14c6430dda Merge branch 'master' into auto-conversion-macro 2021-04-02 16:25:41 +09:00
ToruNiina
e9144b41fb test: returning toml::value directly from into<T> 2020-12-29 18:53:10 +09:00
ToruNiina
0dafa7ee42 test: add case where a table should be inlined
array-of-table implicitly defines an array. If the array itself has a
comment, we need to format it explicitly.
2020-10-18 20:45:12 +09:00
ToruNiina
bfae1ab86c test: add test for auto-generated conversion 2020-10-16 21:40:54 +09:00
ToruNiina
290dca3d67 test: add test for comment duplication 2020-10-13 22:04:28 +09:00
ToruNiina
ba7d49f452 test: use normal string literal
as a workaround for older version of gcc
2020-09-19 19:08:20 +09:00
ToruNiina
b0784ce286 test: in case of comment-before-comma 2020-09-19 18:24:23 +09:00
ToruNiina
84fb703e04 ci: add utf-8 option to MSVC 2020-09-19 00:41:05 +09:00
ToruNiina
8c2560761b chore: enable to use __cplusplus on MSVC
related: https://github.com/ToruNiina/toml11/issues/112
2020-09-19 00:40:44 +09:00
ToruNiina
07ea5e52e2 ci: pass REQ_FS_LIB=ON in case of g++-8 & C++20 2020-09-16 22:16:20 +09:00
ToruNiina
528031012d test: add test for u8""_toml literals 2020-09-16 21:25:38 +09:00
ToruNiina
c205c762fe test: remove needless u8s from ascii characters 2020-09-16 21:25:04 +09:00
ToruNiina
c8ff302c94 test: add test for no-eof-newline cases 2020-09-14 16:39:05 +09:00
ToruNiina
79ddcaece6 chore: add CMake option to link with (std)c++fs 2020-08-06 16:29:24 +09:00