[llvm] r305519 - UnitTests: Replace some if(x)report_fatal_error() with EXPECT_TRUE(!x)

David Blaikie via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 15:52:06 PDT 2017


Ah,looks like ASSERT_TRUE exits the function through 'return;' so it's only
usable at the top of a test case, unfortunately :/

I guess createTargetMachine could return null, then callers could
ASSERT_TRUE (or non-null, if there's an ASSERT for that) on its result.

On Thu, Jun 15, 2017 at 3:46 PM Matthias Braun <matze at braunis.de> wrote:

> Indeed. Unfortunately I am running into problems now as ASSERT_TRUE
> appears to expand into something ending in "return;" in the error case
> which only works in void functions. Still looking around what the correct
> gtest idiom is.
>
> - Matthias
>
> On Jun 15, 2017, at 3:39 PM, David Blaikie <dblaikie at gmail.com> wrote:
>
> I think these should be ASSERT_TRUE, though - since EXPECT doesn't halt
> execution of the test, so it'll hit UB on the following line where the
> pointer is dereferenced, etc?
>
> On Thu, Jun 15, 2017 at 3:31 PM Matthias Braun via llvm-commits <
> llvm-commits at lists.llvm.org> wrote:
>
>> Author: matze
>> Date: Thu Jun 15 17:31:08 2017
>> New Revision: 305519
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=305519&view=rev
>> Log:
>> UnitTests: Replace some if(x)report_fatal_error() with EXPECT_TRUE(!x)
>>
>> Modified:
>>     llvm/trunk/unittests/MI/LiveIntervalTest.cpp
>>     llvm/trunk/unittests/Target/AArch64/InstSizes.cpp
>>
>> Modified: llvm/trunk/unittests/MI/LiveIntervalTest.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/MI/LiveIntervalTest.cpp?rev=305519&r1=305518&r2=305519&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/unittests/MI/LiveIntervalTest.cpp (original)
>> +++ llvm/trunk/unittests/MI/LiveIntervalTest.cpp Thu Jun 15 17:31:08 2017
>> @@ -151,8 +151,7 @@ body: |
>>    std::unique_ptr<MIRParser> MIR;
>>    std::unique_ptr<Module> M = parseMIR(Context, PM, MIR, *TM, MIRString,
>>                                         "func");
>> -  if (!M)
>> -    report_fatal_error("Could not parse MIR code\n");
>> +  EXPECT_TRUE(M);
>>
>>    PM.add(new TestPass(T));
>>
>>
>> Modified: llvm/trunk/unittests/Target/AArch64/InstSizes.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Target/AArch64/InstSizes.cpp?rev=305519&r1=305518&r2=305519&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/unittests/Target/AArch64/InstSizes.cpp (original)
>> +++ llvm/trunk/unittests/Target/AArch64/InstSizes.cpp Thu Jun 15 17:31:08
>> 2017
>> @@ -21,8 +21,7 @@ std::unique_ptr<TargetMachine> createTar
>>
>>    std::string Error;
>>    const Target *TheTarget = TargetRegistry::lookupTarget(TT, Error);
>> -  if (!TheTarget)
>> -    report_fatal_error("Target not registered");
>> +  EXPECT_TRUE(TheTarget);
>>
>>    return std::unique_ptr<TargetMachine>(
>>        TheTarget->createTargetMachine(TT, CPU, FS, TargetOptions(), None,
>> @@ -59,24 +58,20 @@ void runChecks(
>>    std::unique_ptr<MemoryBuffer> MBuffer =
>> MemoryBuffer::getMemBuffer(MIRString);
>>    std::unique_ptr<MIRParser> MParser =
>>        createMIRParser(std::move(MBuffer), Context);
>> -  if (!MParser)
>> -    report_fatal_error("Couldn't create MIR parser");
>> +  EXPECT_TRUE(MParser);
>>
>>    std::unique_ptr<Module> M = MParser->parseIRModule();
>> -  if (!M)
>> -    report_fatal_error("Couldn't parse module");
>> +  EXPECT_TRUE(M);
>>
>>    M->setTargetTriple(TM->getTargetTriple().getTriple());
>>    M->setDataLayout(TM->createDataLayout());
>>
>>    MachineModuleInfo MMI(TM);
>>    bool Res = MParser->parseMachineFunctions(*M, MMI);
>> -  if (Res)
>> -    report_fatal_error("Couldn't parse MIR functions");
>> +  EXPECT_FALSE(Res);
>>
>>    auto F = M->getFunction("sizes");
>> -  if (!F)
>> -    report_fatal_error("Couldn't find intended function");
>> +  EXPECT_TRUE(F);
>>    auto &MF = MMI.getOrCreateMachineFunction(*F);
>>
>>    Checks(*II, MF);
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170615/cf378e66/attachment.html>


More information about the llvm-commits mailing list