1 //===- not.cpp - The 'not' testing tool -----------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // Will return true if cmd doesn't crash and returns false.
12 // Will return true if cmd crashes (e.g. for testing crash reporting).
14 #include "llvm/Support/Program.h"
15 #include "llvm/Support/WithColor.h"
16 #include "llvm/Support/raw_ostream.h"
20 int main(int argc
, const char **argv
) {
21 bool ExpectCrash
= false;
26 if (argc
> 0 && StringRef(argv
[0]) == "--crash") {
35 auto Program
= sys::findProgramByName(argv
[0]);
37 WithColor::error() << "unable to find `" << argv
[0]
38 << "' in PATH: " << Program
.getError().message() << "\n";
42 std::vector
<StringRef
> Argv
;
44 for (int i
= 0; i
< argc
; ++i
)
45 Argv
.push_back(argv
[i
]);
47 int Result
= sys::ExecuteAndWait(*Program
, Argv
, None
, {}, 0, 0, &ErrMsg
);
49 // Handle abort() in msvcrt -- It has exit code as 3. abort(), aka
50 // unreachable, should be recognized as a crash. However, some binaries use
51 // exit code 3 on non-crash failure paths, so only do this if we expect a
53 if (ExpectCrash
&& Result
== 3)
57 WithColor::error() << ErrMsg
<< "\n";