31 Commits

Author SHA1 Message Date
dumb-kevin 77a999f2fa Mark TU-local helper templates static
- use_amount_stack template in map.cpp is only used inside the TU
- npc_pickup_from_stack template in npcmove.cpp is only used inside the TU
- silences misc-use-internal-linkage
2026-05-09 10:02:28 +04:00
akrieger 7de68332af Use fmt instead of string_formatter 2026-01-13 09:06:26 -08:00
moxian 2ee44002fd Mechanically IWYU the tests
python3 ~/github/include-what-you-use/iwyu_tool.py -j5 -p build $( find
src/ tests/ -maxdepth 1 -name '*.cpp' | grep -v -f
tools/iwyu/bad_files.txt )  --  -Xiwyu --comment_style=long -Xiwyu -
-max_line_length=1000 -Xiwyu --cxx17ns -Xiwyu
--mapping_file=../tools/iwyu/cata.imp   | tee out/iwyu/f-a-01.txt >
/dev/null

followed by

cat out/iwyu/f-a-02.txt | python3
~/github/include-what-you-use/fix_includes.py --reorder --nosafe_headers

followed by manual fixups of <stddef.h> -> <cstddef> and similar.

tests/generic_factory_test.cpp gets mangled very badly (IWYU bug) so
it's excluded from the list.

Code size:
includes:
$ cat obj/tiles/*.inc | wc
 288068  576136 17898260
$ cat tests/obj/tiles/*.inc | wc
 167044  334088 10465766

post-processed source (clang -E):
./make_preproc.sh src/
68567896 177775140 2134075721
./make_preproc.sh tests/
39341957 102891720 1243323710
2025-02-10 00:46:57 -08:00
andrei 37ed546f5e tests: fix locale-dependent tests (#66065) 2023-06-13 12:28:16 -07:00
John Bytheway d3c271b9e4 Modernize string_formatter
Update string formatter code in a few ways, taking advantage of C++17:
- Allow string_view as the format string.
- Allow string_view to be a formatted argument (via %s).
- Simplify the metaprogramming using alias templates and variable
  templates.

astyle really struggles to style this code reasonably.  I had to add
some extra newlines to avoid some situations where astyle got into an
infinite loop of going back and forth between options.
2023-04-11 20:21:31 -04:00
John Bytheway ebd549b300 Fix StringMaker ODR violations in tests
Catch2 provides a customization point for converting our types to
strings by specializing the StringMaker template.

We have some specializations in stringmaker.h, but this feature was only
working intermittently.  I finally figured out that was due to an ODR
violation.  The test files that didn't include stringmaker.h were
compiling a different specialization than the ones that did.

Re-jig the test includes so that any file including catch.hpp also
includes stringmaker.h, thereby ensuring that the custom
specializations are used everywhere and there is no ODR violation.

I achieved this by adding a new cata_catch.h header and making all
existing headers include catch.hpp via the new header.
2021-07-03 07:42:06 -07:00
John Bytheway 094e2440b3 Omit tests that are failing on Mingw (#48622)
* Omit tests that are failing on Mingw

These string_formatter tests fail on Mingw and it looks like it's simply
a bug in the standard library there.  I don't know that we can
reasonably fix them (short of implementing printf ourselves) and they're
showing up in the GitHub UI for every PR, which is potentially confusing
for contributors.

* Remove !mayfail marking on string_formatter test

This should no longer be expected to fail, with the troublesome tests
excised.
2021-07-03 07:42:06 -07:00
alef 678cf6afcd Fix string formatter test in MSVC >= 16.2 (#48236) 2021-03-29 00:10:20 +03:00
Binrui Dong 9fdb7ef59c Run IWYU
* Change _ctype.h and __locale to cctype and clocale

* Change _wctype.h to cwctype in game.cpp

* Change __functional_base to functional

* Remove libcxx internal headers

* Remove UNIX system headers

* Fix clang-tidy error with -nostdinc++
2021-02-06 00:18:41 -05:00
Kevin Granade 6d1841ac67 Precompiled Catch2 header (#42453)
* Hoist catch.hpp include to the top of files

* Precompile the catch header in tests
2020-07-29 01:28:26 +03:00
ZhilkinSerg 2fd202b492 Merge pull request #41973 from jbytheway/format_test_tweaks
Tweak string_formatter test for better errors
2020-07-09 22:08:52 +03:00
John Bytheway fe88cf523b Mark string_formatter test [!mayfail]
This is failing on Visual Studio with no sign of a fix coming soon.  The
failure isn't super critical, and the code under test is not likely to
change, so marking this test mayfail should be pretty low risk.
2020-07-09 09:58:00 -04:00
John Bytheway a24465f2ea Tweak string_formatter test for better errors
The existing string_formatter test has a weird behaviour where a bunch
of unrelated things that were CAPTUREd get printed out when any of the
tests fail.  This can be seen in the current Appveyor test failures.  I
think this is actually a Catch2 bug, or possibly a limitation of how
Catch2 implements required-throw tests, but I'm too lazy to investigate
that so I'm just working around it.

Basically, the tests that throw an error are not removing their strings
from Catch2's output state, so they are still printed out for later test
failures even though they are unrelated.

Fix by separating out the throw-based tests into a separate test case.
2020-07-09 09:21:41 -04:00
John Bytheway 095bd51974 Use C++-style includes
Convert all C library includes to their C++ equivalents (stdio.h ->
cstdio, etc.).
2019-12-24 17:04:16 -05:00
Jianxiang Wang (王健翔) 1f0b039c99 Enable the clang-tidy text style check (#34837)
* Disable space check after unicode ellipses

* Fix spacing

* Suppress false positives

* Do not remove spaces before ellipses and colons to suppress false positives

* Fix spacing of raw strings

* Update text style check test

* Enable cata-text-style
2019-10-18 20:26:00 +03:00
John Bytheway 19f0f67928 clang-tidy bugprone-use-after-move (#33557)
* Enable bugprone-use-after-move

Enable this clang-tidy check and deal with associated warnings.

Mostly these were suppressions for things in the tests that are
specifically testing move constructor semantics, but one case was a
genuine latent bug.

* Fix mismatched declaration name

This error seems to have crept into master.
2019-08-26 13:17:04 +03:00
John Bytheway ee9f22ca12 Avoid unnecessary copy initialization
Refactor or suppress clang-tidy warnings about unnecessary
copy-initialization.
2019-07-29 14:36:12 -04:00
John Bytheway 4321c025d2 IWYU 20190629 (#31990)
* Add IWYU pragma: keep

* Run IWYU and astyle

* Run IWYU a second time

* Prevent #include <cxxabi.h>

Unclear why IWYU thinks this is needed.  It isn't, and it causes
problems on Visual Studio.
2019-07-01 12:25:53 +03:00
John Bytheway dfb9ad5ca3 Support printing with ptrdiff_t length modifier
In printf (at least in POSIX) you can print a ptrdiff_t value with e.g.
%td.  Make that an option for our string formatting also.
2019-06-16 21:06:11 +01:00
John Bytheway 65b592c4c2 Disable format warning
This is a true warning, but we don't want to see it because the whole
point of the code is to test whether this non-portable feature works.
2019-05-17 19:28:50 +01:00
John Bytheway e3e7700aef Apply IWYU changes
This is a run of IWYU followed by astyle.
2019-04-22 11:42:51 +01:00
John Bytheway b0576393e3 Sort headers according to IWYU conventions
A first step towards IWYU support.  Doing the sorting first because it
makes reviewing any additions or removals of headers much simpler.

The IWYU order is:
- Associated headers
- Misc system headers
- C++ STL headers
- Other project headers

The biggest change is moving system headers before project headers (they
are usually afterwards in Cata at the moment.

The associated header for a cpp file is the header file which declares
the functions defined in that cpp file.  Normally that's the one which
shares the same name (up to extension), and if so IWYU figures it out
automatically.

However, in this project there are many corner cases, so we need to use
IWYU pragma: associated to tell it which header (or, in some cases,
which headers) is the associated header.  We are unusual in having
multiple associated headers for some files, which might lead to
discovering some interesting IWYU bugs later, but in theory it is
supported.
2019-01-05 14:03:31 +00:00
ZhilkinSerg f8eb2acd05 Optimized includes (tests) 2018-11-07 03:55:47 +03:00
Kevin Granade 9b8fb338c1 Revert "Treat format strings without arguments as pure string" (#25913) 2018-09-30 21:15:53 +00:00
Qrox a477249b44 Update test cases in string_formatter_test.cpp 2018-09-29 23:29:46 +08:00
Kevin Granade 5c5b2a84a4 Disable now-invalid string formatter tests. 2018-04-29 19:51:40 +00:00
BevapDin ba58017770 Merge vstring_format into string_formatter::raw_string_format
That was the only place that actually called it anyway.

Now there is only one function: `raw_string_format` (which is now public in `string_formatter` so the test code can call it).
2018-04-29 19:51:40 +00:00
BevapDin 7486992a4a Fix for mingw builds using format specifier I64 instead of ll
mingw does not use "ll" for `long long int`, one has to use "I64" instead (or "I32" when `long long int` is only 32 bit).
2017-11-03 22:53:27 +01:00
BevapDin f608ac14e6 Don't test raw string format with positional arguments when it's not supported. 2017-11-03 22:53:27 +01:00
BevapDin 4f2a173bc4 Move raw_string_format into class string_formatter
That class is the only place that uses it.
2017-11-03 22:53:25 +01:00
BevapDin 00a6ca2f56 Implement type safe sprintf wrapper string_formatter
- Rename `string_format` to `raw_string_format`.
- Removed the overload of `string_format` that takes a `std::string`. The other overload (taking a `const char*`) will be used instead.

Add `string_formatter` class and helper function `string_format` (which takes the place of the previously removed / renamed version).
As the implementation of it is in another header, include the new header "string_formatter.h" where it is used.

Add tests for the new code.
2017-10-21 14:48:56 +02:00