Commit Graph

37 Commits

Author SHA1 Message Date
Seth R. Johnson e4dd555000
Use python3 shebang for all python scripts
The `python` command may not exist on a system with Python 3 installed.
See https://peps.python.org/pep-0394/ for a discussion of the commands
expected to be installed.

Since Python2 was officially sunsetted almost three years ago
(https://www.python.org/doc/sunset-python-2/), IWYU should prefer
compatibility with newer systems over older ones.

Python code in scripts is still Python3/Python2-compatible, but we will no
longer make an effort to preserve Python2 support over time.

Fixes #1096.
2022-12-16 21:03:39 +01:00
Kim Gräsman 6fa29afb5c Make it possible to verify exit code in tests
It is now possible to append a parenthesized exit code to the summary start
marker: '/**** IWYU_SUMMARY(1)' to indicate that IWYU should return exit
code 1 for this test.

The exit-code syntax is only parsed out of the main file under test (not
e.g. check-also or associated files).

The exit code marker is entirely optional, and most tests shouldn't care
about exit codes.
2022-02-26 12:21:26 +01:00
Kim Gräsman 83b30c22d2 Reflow comment 2022-02-20 16:28:21 +01:00
Alexey Storozhev 8506c4057a Delete the first argument of TestIwyuOnRelativeFile
Decouple the function from an instance of unittest.TestCase.
2021-05-01 17:06:44 +02:00
Alexey Storozhev cb259fdd27 Delete IWYU launch arguments editing from test runner
This functionality is fully covered with IWYU_ARGS.
2021-01-31 11:07:48 +01:00
Alexey Storozhev bc0ec65ec0 Parse IWYU arguments from test files.
Some of source files require extra Clang or IWYU arguments like
`-std=c++17` or `--mapping_file=...`.

Before this change all these args were stored in `run_iwyu_tests.py`.

This change adds the concept of "ARGS lines" so the launch arguments
could be specified directly in a source file that represents a test case.

Inspired by RUN lines of `lit` in LLVM:
https://llvm.org/docs/TestingGuide.html, "Writing new regression tests".
2021-01-31 11:07:48 +01:00
Alexey Storozhev edd7f96fb2 Simplify _StripCommentFromLine 2020-12-06 18:15:02 +01:00
Kim Grasman b280c3fd6f [python] Clean up license headers
Apply all changes suggested by iwyu-check-license-header.py to get
strictly conforming license headers.
2019-12-04 21:42:46 +01:00
Kim Grasman f09dba6934 Clean up output from test runner
* Only quote the IWYU executable name when necessary
* Remove logging of IWYU and Clang flags, they are already visible on
  the command-line
2016-08-15 21:08:28 +02:00
Volodymyr Sapsai 2f826a3323 Don't require grep to run tests. 2016-08-08 22:34:41 -07:00
Volodymyr Sapsai d5cfaf0db3 Fix in tests "fatal error: file not found", make test suite detect such issue.
Issue was exposed by commit 62bc551.
2016-06-08 22:14:58 -07:00
Flamefire 62bc551a56 Don't assume . as an include path for tests
The test running framework would always add `-I .` as an argument
to Clang. This makes it very hard to test examples without explicit
include paths, and has driven IWYU's behavior to assume the presence
of `-I .`.

In order to fix bugs related to this, we now make `-I .` explicit
for the tests that actually need it.

Patch by Flamefire, thanks!
2016-04-28 21:47:58 +02:00
Kim Grasman b5743df947 Fix #231: Allow spaces in paths in test runner 2015-11-13 22:15:48 +01:00
Kim Grasman 87c53c392a Fix #216: Allow user to specify IWYU path to test
Add an optional command-line argument to run_iwyu_tests.py, to specify
which IWYU binary to test with. Usage example:

  $ ./run_iwyu_tests.py -- ./include-what-you-use

The '--' delimiter is used to separate args going to Python's unittest
from the new arg used by the test runner.

Update docs to mention new run_iwyu_tests.py features.
2015-10-01 06:11:22 +02:00
Kim Grasman f153fe5dbe Update shebangs to find Python in PATH. 2015-08-04 10:56:23 +02:00
Kim Grasman 49f85101d3 Fix ResourceWarning when using Python 3 2015-07-23 23:18:11 +02:00
Kim Gräsman 2dcf849ee3 Normalize line endings in IWYU output before attempting assertions.
LLVM commit r199057 causes llvm::errs() to print CRLF instead of LF on Windows. Normalize all tool output to LF.
2014-01-18 20:40:44 +00:00
Kim Gräsman 9fc1d5dc27 Fix issue 116: have tests search for IWYU in heuristic, hard-coded paths first and then fall back on system PATH. 2013-12-27 08:37:44 +00:00
Volodymyr Sapsai 51e45c1f4f Ignore null types during recursive visiting (resolves issue #79).
Within templates deduced type of AutoType is null and using null type causes
an assertion failure.
2013-01-03 09:07:33 +00:00
Volodymyr Sapsai 5944806a41 Added default mapping file. Patch by Kim Gräsman.
The --mapping_file argument now defaults to "iwyu.gcc.imp" if no other
mapping files are provided.
2012-12-02 15:12:25 +00:00
Volodymyr Sapsai a6c6e5238c Read private to public mappings from external file. Patch by Kim Gräsman. 2012-10-14 22:39:30 +00:00
Volodymyr Sapsai c0239eb383 Avoid throwing exceptions in _PortableNext (finally resolves issue #51).
Instead of trying to call iterator.next() and catching exception, check if 
iterator has method next.  Thus thread doesn't stay in exception state.
Patch by Kim Gräsman.
2012-07-19 22:14:17 +00:00
Volodymyr Sapsai 3c19e1d711 Added more IWYU search paths, for out-of-tree build.
When follow Clang 'Getting Started' instructions you end up with directories
llvm-root/build, llvm-root/llvm/tools/clang/tools/include-what-you-use. And to
access build directory you have to use path ../../../../../build.
Patch by Kim Gräsman.
2012-06-19 19:35:06 +00:00
Volodymyr Sapsai 7fca86b77a Run run_iwyu_tests.py cleanly under Python 3.2.
Added _PortableNext(iterator) function which provides version-independent
interface for iterator.next() and next(iterator). Patch by Kim Gräsman.
2012-06-12 21:16:57 +00:00
FFabioFracassi b52e7fcf91 Fixed Constructor handling for clang post r150682 (solves issue 65) 2012-03-10 14:04:37 +00:00
csilvers+iwyu a15c84b30c Don't ask me why, but the automated system I use for updating patches wants to undo Paul Holden's latest patches and then re-apply them. I'm sure there's a way to skip doing that, but I don't know what it is, so I'm going to let it do its thing. This is step 2 (the re-apply).
Revision created by MOE tool push_codebase.
MOE_MIGRATION=2806
2011-08-01 20:58:24 +00:00
csilvers+iwyu 60272bf071 Don't ask me why, but the automated system I use for updating patches wants to undo Paul Holden's latest patches and then re-apply them. I'm sure there's a way to skip doing that, but I don't know what it is, so I'm going to let it do its thing. This is step 1 (the revert).
Revision created by MOE tool push_codebase.
MOE_MIGRATION=2805
2011-08-01 20:57:19 +00:00
paul.holden 8e90bd0bce Make a number of small changes to better support python 3.2, and when running on Windows. This script has been tested under python 2.4, 2.7 and 3.2. There is still one remaining issue left in order to get this running cleanly under python 3.2, namely fixing the use of 'this_failure.next()', which needs to become something like 'next(this_failure)'. This mostly resolves http://code.google.com/p/include-what-you-use/issues/detail?id=51. Reviewed by csilvers. 2011-07-21 07:36:31 +00:00
csilvers+iwyu 72ac42cac0 Improve our handling of the 'sanity check' case where we add
an #include of a .cc.  We now check more directly for the bad
case: suggesting to add a .cc #include (we allow you to keep
an existing one, though).  This requires us doing the check
later in the process, which is good -- sanity-checks *should*
be done right before emitting output.  It also allows me to
relax the check to include #including .cc files from other .cc
files (which is what caused the bug that prompted this CL).

I had to modify the test framework to consider .c files --
since .cc files are special to run_iwyu_tests.cc, when I have
to #include a .cc file in my tests, I actually #include a .c
file, which is the same as far as iwyu is concerned.

R=wan,dsturtevant
DELTA=133  (80 added, 41 deleted, 12 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1278
2011-04-06 20:08:36 +00:00
csilvers+iwyu eb68790ba7 Redo the rest of the clang changes that had gotten pushed around r63, but had been accidentally reverted with some of these other updates.
Revision created by MOE tool push_codebase.
MOE_MIGRATION=921
2011-03-18 07:00:52 +00:00
csilvers d11b2a8ba3 Reapply the changes to parse commandline flags. This, and some other
changes, were accidentally undone in a recent commit.  I'll re-do all
these changes over the next few commits.

Revision created by MOE tool push_codebase.
MOE_MIGRATION=897
2011-03-18 03:00:56 +00:00
csilvers+iwyu 7e94050119 Revamped the error reporting code again. Simpler & symmetric.
R=csilvers
DELTA=57  (0 added, 23 deleted, 34 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=894
2011-03-18 02:52:53 +00:00
csilvers+iwyu 58a3534fdc Revamped the iwyu_test_util assertion error reporting to make it more
apparent what the diffs are.

R=csilvers
DELTA=75  (23 added, 15 deleted, 37 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=893
2011-03-18 02:52:29 +00:00
csilvers+iwyu a88e680b04 I knew that there would be trouble if I tried to call
HasMapping before mappings were finalized.  And indeed, the
glob mappings were being left out.  I solve this by doing the
reexport-protection check after mappins are finalized, in the
preprocessor.

While in the area, I added a few include-picker mappings that
had been inadvertently omitted before, or discovered in
testing.  In particular, glob defines its own size_t, which is
weird; we don't want to depend on glob for size_t.

R=dsturtevant
DELTA=141  (129 added, 2 deleted, 10 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=889
2011-03-18 02:51:02 +00:00
csilvers 9fac1cd679 Allow finding _IWYU_PATH in one of several locations. This way we can
run the test for release builds as well.  Based on a patch by
tonyg@chromium.org, modified to do the searching at module-load time
(trading simplicity for a bit of impurity).

Resolves http://code.google.com/p/include-what-you-use/issues/detail?id=21
2011-03-15 19:20:19 +00:00
csilvers+iwyu d9c28a9038 Move the check_also test to tests/, so it can run under the
run_iwyu_tests framework.  This is the first use of the
_iwyu_flags_map framework, which had to be fixed up a bit to
work.

To help debugging problems, I added in some more logging
information, which I've kept.

I also noticed that tests weren't running on my stock ubuntu
python.  This seems to be because the stock unittest module
doesn't run the global setUp in main.  So I renamed the global
setUp and now call it manually.

R=dsturtevant
DELTA=250  (117 added, 121 deleted, 12 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=729
2011-03-04 00:24:20 +00:00
csilvers dee92b5e0a Initial release! Grains of salt not included. 2011-02-04 22:28:15 +00:00