llvm.org GIT mirror llvm / 159e008
[FileCheck] Use bool operator to test Expected Use bool() consistently to get boolean value of Error, Optional and Expected types in EXPECT calls. While static_cast is used in all cases but one, bool provides more clarity and makes more sense as a new default. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365644 91177308-0d34-0410-b5e6-96231b3b80d8 Thomas Preud'homme 3 months ago
1 changed file(s) with 24 addition(s) and 24 deletion(s). Raw diff Collapse all Expand all
4747
4848 // Defined variable: eval returns right value.
4949 Expected Value = Expression.eval();
50 EXPECT_TRUE(static_cast(Value));
50 EXPECT_TRUE(bool(Value));
5151 EXPECT_EQ(60U, *Value);
5252
5353 // Undefined variable: eval fails, undefined variable returned. We call
8686 bool IsPseudo = true;
8787 Expected ParsedName =
8888 FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
89 EXPECT_TRUE(static_cast(ParsedName));
89 EXPECT_TRUE(bool(ParsedName));
9090 EXPECT_EQ(*ParsedName, OrigVarName);
9191 EXPECT_TRUE(VarName.empty());
9292 EXPECT_FALSE(IsPseudo);
9494 VarName = OrigVarName = bufferize(SM, "$GoodGlobalVar");
9595 IsPseudo = true;
9696 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
97 EXPECT_TRUE(static_cast(ParsedName));
97 EXPECT_TRUE(bool(ParsedName));
9898 EXPECT_EQ(*ParsedName, OrigVarName);
9999 EXPECT_TRUE(VarName.empty());
100100 EXPECT_FALSE(IsPseudo);
102102 VarName = OrigVarName = bufferize(SM, "@GoodPseudoVar");
103103 IsPseudo = true;
104104 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
105 EXPECT_TRUE(static_cast(ParsedName));
105 EXPECT_TRUE(bool(ParsedName));
106106 EXPECT_EQ(*ParsedName, OrigVarName);
107107 EXPECT_TRUE(VarName.empty());
108108 EXPECT_TRUE(IsPseudo);
118118 VarName = OrigVarName = bufferize(SM, "B@dVar");
119119 IsPseudo = true;
120120 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
121 EXPECT_TRUE(static_cast(ParsedName));
121 EXPECT_TRUE(bool(ParsedName));
122122 EXPECT_EQ(VarName, OrigVarName.substr(1));
123123 EXPECT_EQ(*ParsedName, "B");
124124 EXPECT_FALSE(IsPseudo);
126126 VarName = OrigVarName = bufferize(SM, "B$dVar");
127127 IsPseudo = true;
128128 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
129 EXPECT_TRUE(static_cast(ParsedName));
129 EXPECT_TRUE(bool(ParsedName));
130130 EXPECT_EQ(VarName, OrigVarName.substr(1));
131131 EXPECT_EQ(*ParsedName, "B");
132132 EXPECT_FALSE(IsPseudo);
134134 VarName = bufferize(SM, "BadVar+");
135135 IsPseudo = true;
136136 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
137 EXPECT_TRUE(static_cast(ParsedName));
137 EXPECT_TRUE(bool(ParsedName));
138138 EXPECT_EQ(VarName, "+");
139139 EXPECT_EQ(*ParsedName, "BadVar");
140140 EXPECT_FALSE(IsPseudo);
142142 VarName = bufferize(SM, "BadVar-");
143143 IsPseudo = true;
144144 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
145 EXPECT_TRUE(static_cast(ParsedName));
145 EXPECT_TRUE(bool(ParsedName));
146146 EXPECT_EQ(VarName, "-");
147147 EXPECT_EQ(*ParsedName, "BadVar");
148148 EXPECT_FALSE(IsPseudo);
150150 VarName = bufferize(SM, "BadVar:");
151151 IsPseudo = true;
152152 ParsedName = FileCheckPattern::parseVariable(VarName, IsPseudo, SM);
153 EXPECT_TRUE(static_cast(ParsedName));
153 EXPECT_TRUE(bool(ParsedName));
154154 EXPECT_EQ(VarName, ":");
155155 EXPECT_EQ(*ParsedName, "BadVar");
156156 EXPECT_FALSE(IsPseudo);
357357 FileCheckStringSubstitution StringSubstitution =
358358 FileCheckStringSubstitution(&Context, "VAR404", 42);
359359 Expected SubstValue = StringSubstitution.getResult();
360 EXPECT_FALSE(static_cast(SubstValue));
360 EXPECT_FALSE(bool(SubstValue));
361361 expectUndefError("VAR404", SubstValue.takeError());
362362
363363 // Substitutions of defined pseudo and non-pseudo numeric variables return
371371 FileCheckNumericSubstitution SubstitutionN =
372372 FileCheckNumericSubstitution(&Context, "N", &NExpression, 30);
373373 Expected Value = SubstitutionLine.getResult();
374 EXPECT_TRUE(static_cast(Value));
374 EXPECT_TRUE(bool(Value));
375375 EXPECT_EQ("42", *Value);
376376 Value = SubstitutionN.getResult();
377 EXPECT_TRUE(static_cast(Value));
377 EXPECT_TRUE(bool(Value));
378378 EXPECT_EQ("13", *Value);
379379
380380 // Substitution of an undefined numeric variable fails.
381381 LineVar.clearValue();
382382 SubstValue = SubstitutionLine.getResult().takeError();
383 EXPECT_FALSE(static_cast(SubstValue));
383 EXPECT_FALSE(bool(SubstValue));
384384 expectUndefError("@LINE", SubstValue.takeError());
385385 NVar.clearValue();
386386 SubstValue = SubstitutionN.getResult().takeError();
387 EXPECT_FALSE(static_cast(SubstValue));
387 EXPECT_FALSE(bool(SubstValue));
388388 expectUndefError("N", SubstValue.takeError());
389389
390390 // Substitution of a defined string variable returns the right value.
391391 FileCheckPattern P = FileCheckPattern(Check::CheckPlain, &Context, 1);
392392 StringSubstitution = FileCheckStringSubstitution(&Context, "FOO", 42);
393393 Value = StringSubstitution.getResult();
394 EXPECT_TRUE(static_cast(Value));
394 EXPECT_TRUE(bool(Value));
395395 EXPECT_EQ("BAR", *Value);
396396 }
397397
459459 LocalNumVarRef, DefinedNumericVariable, SM);
460460 Expected EmptyVar = Cxt.getPatternVarValue(EmptyVarStr);
461461 Expected UnknownVar = Cxt.getPatternVarValue(UnknownVarStr);
462 EXPECT_TRUE(static_cast(LocalVar));
462 EXPECT_TRUE(bool(LocalVar));
463463 EXPECT_EQ(*LocalVar, "FOO");
464 EXPECT_TRUE(static_cast(Expression));
464 EXPECT_TRUE(bool(Expression));
465465 Expected ExpressionVal = (*Expression)->eval();
466 EXPECT_TRUE(static_cast(ExpressionVal));
466 EXPECT_TRUE(bool(ExpressionVal));
467467 EXPECT_EQ(*ExpressionVal, 18U);
468 EXPECT_TRUE(static_cast(EmptyVar));
468 EXPECT_TRUE(bool(EmptyVar));
469469 EXPECT_EQ(*EmptyVar, "");
470470 EXPECT_TRUE(errorToBool(UnknownVar.takeError()));
471471
497497 StringRef GlobalVarStr = "$GlobalVar";
498498 StringRef GlobalNumVarRef = bufferize(SM, "$GlobalNumVar");
499499 Expected GlobalVar = Cxt.getPatternVarValue(GlobalVarStr);
500 EXPECT_TRUE(static_cast(GlobalVar));
500 EXPECT_TRUE(bool(GlobalVar));
501501 EXPECT_EQ(*GlobalVar, "BAR");
502502 P = FileCheckPattern(Check::CheckPlain, &Cxt, 3);
503503 Expression = P.parseNumericSubstitutionBlock(GlobalNumVarRef,
504504 DefinedNumericVariable, SM);
505 EXPECT_TRUE(static_cast(Expression));
505 EXPECT_TRUE(bool(Expression));
506506 ExpressionVal = (*Expression)->eval();
507 EXPECT_TRUE(static_cast(ExpressionVal));
507 EXPECT_TRUE(bool(ExpressionVal));
508508 EXPECT_EQ(*ExpressionVal, 36U);
509509
510510 // Clear local variables and check global variables remain defined.
513513 P = FileCheckPattern(Check::CheckPlain, &Cxt, 4);
514514 Expression = P.parseNumericSubstitutionBlock(GlobalNumVarRef,
515515 DefinedNumericVariable, SM);
516 EXPECT_TRUE(static_cast(Expression));
516 EXPECT_TRUE(bool(Expression));
517517 ExpressionVal = (*Expression)->eval();
518 EXPECT_TRUE(static_cast(ExpressionVal));
518 EXPECT_TRUE(bool(ExpressionVal));
519519 EXPECT_EQ(*ExpressionVal, 36U);
520520 }
521521 } // namespace