Skip to content
15 changes: 9 additions & 6 deletions clang-tools-extra/include-cleaner/test/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,15 @@ int x = foo();
// RUN: FileCheck --match-full-lines --check-prefix=EDIT2 %s < %t.cpp
// EDIT2-NOT: {{^}}#include "foo.h"{{$}}

// This test has commands that rely on shell capabilities that won't execute
// correctly on Windows e.g. subshell execution
// REQUIRES: shell
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't just affect that particular run, affects the whole, can you move the test into its own file ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was explained in the previous comment. It now works on Windows as well.

// RUN: mkdir -p $(dirname %t)/out
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can use %T instead of dirname %t, you can find full list in https://llvm.org/docs/CommandGuide/lit.html#substitutions, same below.

also it's safer to run a rm -rf %T beforehand to make sure we're starting clean

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It turns out %T is also deprecated. I replaced my shell invocation with %t.dir, as this is the recommended method, as described in https://reviews.llvm.org/D69572. I also slightly modified the test invocation so that it works on Windows as well. (Tested on a local Windows machine.)

// RUN: cp %s %t.cpp
// RUN: echo "[{\"directory\":\"$(dirname %t)/out\",\"file\":\"../$(basename %t).cpp\",\"command\":\":clang++ -I%S/Inputs/ ../$(basename %t).cpp\"}]" > $(dirname %t)/out/compile_commands.json
// RUN: pushd $(dirname %t)
// RUN: clang-include-cleaner -p out -edit $(basename %t).cpp
// RUN: popd
// RUN: FileCheck --match-full-lines --check-prefix=EDIT3 %s < %t.cpp
// EDIT3: #include "foo.h"
// EDIT3-NOT: {{^}}#include "foobar.h"{{$}}
// RUN: pushd $(dirname %t)
// RUN: clang-include-cleaner -p out -edit $(basename %t).cpp
// RUN: popd
// RUN: FileCheck --match-full-lines --check-prefix=EDIT3 %s < %t.cpp
// EDIT3: #include "foo.h"
// EDIT3-NOT: {{^}}#include "foobar.h"{{$}}
Loading