Skip to content

Commit

Permalink
[llvm][unittests] Don't call raw_string_ostream::flush() (NFC)
Browse files Browse the repository at this point in the history
raw_string_ostream::flush() is essentially a no-op (also specified in docs).
Don't call it in tests that aren't meant to test 'raw_string_ostream' itself.

p.s. remove a few redundant calls to raw_string_ostream::str()
  • Loading branch information
JOE1994 committed Sep 13, 2024
1 parent c010b72 commit 459a82e
Show file tree
Hide file tree
Showing 32 changed files with 13 additions and 101 deletions.
1 change: 0 additions & 1 deletion llvm/unittests/ADT/RewriteBufferTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ static std::string writeOutput(const RewriteBuffer &Buf) {
std::string Result;
raw_string_ostream OS(Result);
Buf.write(OS);
OS.flush();
return Result;
}

Expand Down
4 changes: 0 additions & 4 deletions llvm/unittests/DebugInfo/DWARF/DWARFDebugFrameTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ void expectDumpResult(const dwarf::CIE &TestCIE, bool IsEH,
auto DumpOpts = DIDumpOptions();
DumpOpts.IsEH = IsEH;
TestCIE.dump(OS, DumpOpts);
OS.flush();
StringRef FirstLine = StringRef(Output).split('\n').first;
EXPECT_EQ(FirstLine, ExpectedFirstLine);
}
Expand All @@ -56,7 +55,6 @@ void expectDumpResult(const dwarf::FDE &TestFDE, bool IsEH,
auto DumpOpts = DIDumpOptions();
DumpOpts.IsEH = IsEH;
TestFDE.dump(OS, DumpOpts);
OS.flush();
StringRef FirstLine = StringRef(Output).split('\n').first;
EXPECT_EQ(FirstLine, ExpectedFirstLine);
}
Expand Down Expand Up @@ -344,7 +342,6 @@ void expectDumpResult(const dwarf::UnwindLocation &Loc,
std::string Output;
raw_string_ostream OS(Output);
OS << Loc;
OS.flush();
StringRef FirstLine = StringRef(Output).split('\n').first;
EXPECT_EQ(FirstLine, ExpectedFirstLine);
}
Expand Down Expand Up @@ -387,7 +384,6 @@ void expectDumpResult(const dwarf::RegisterLocations &Locs,
std::string Output;
raw_string_ostream OS(Output);
OS << Locs;
OS.flush();
StringRef FirstLine = StringRef(Output).split('\n').first;
EXPECT_EQ(FirstLine, ExpectedFirstLine);
}
Expand Down
2 changes: 0 additions & 2 deletions llvm/unittests/DebugInfo/DWARF/DWARFDebugLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,6 @@ TEST_F(DebugLineBasicFixture, VerboseOutput) {
raw_string_ostream OS(Output);
Parser.parseNext(RecordRecoverable, RecordUnrecoverable, &OS,
/*Verbose=*/true);
OS.flush();
StringRef OutputRef(Output);

size_t Pos = 0;
Expand Down Expand Up @@ -1805,7 +1804,6 @@ struct TruncatedOpcodeFixtureBase : public CommonFixture {
raw_string_ostream OS(Output);
Parser.parseNext(RecordRecoverable, RecordUnrecoverable, &OS,
/*Verbose=*/true);
OS.flush();

std::string LinePrefix =
("0x0000002f: 0" + Twine::utohexstr(OpcodeValue) + " ").str();
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ TEST_P(DumpValueFixture, Test) {
Opts.ShowAddresses = true;

Form.dump(OS, Opts);
OS.flush();

EXPECT_EQ(Output, ExpectedResult);
}
Expand Down
6 changes: 0 additions & 6 deletions llvm/unittests/DebugInfo/GSYM/GSYMTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3802,7 +3802,6 @@ TEST(GSYMTest, TestRangeWarnings) {
const uint32_t ThreadCount = 1;
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
OS.flush();
SmallString<512> Str;
raw_svector_ostream OutStrm(Str);
const auto ByteOrder = llvm::endianness::native;
Expand Down Expand Up @@ -4005,7 +4004,6 @@ TEST(GSYMTest, TestEmptyRangeWarnings) {
const uint32_t ThreadCount = 1;
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
OS.flush();
SmallString<512> Str;
raw_svector_ostream OutStrm(Str);
const auto ByteOrder = llvm::endianness::native;
Expand Down Expand Up @@ -4158,7 +4156,6 @@ TEST(GSYMTest, TestEmptyLinkageName) {
const uint32_t ThreadCount = 1;
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
OS.flush();
SmallString<512> Str;
raw_svector_ostream OutStrm(Str);
const auto ByteOrder = llvm::endianness::native;
Expand Down Expand Up @@ -4320,7 +4317,6 @@ TEST(GSYMTest, TestLineTablesWithEmptyRanges) {
const uint32_t ThreadCount = 1;
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
OS.flush();
SmallString<512> Str;
raw_svector_ostream OutStrm(Str);
const auto ByteOrder = llvm::endianness::native;
Expand Down Expand Up @@ -4641,7 +4637,6 @@ TEST(GSYMTest, TestHandlingOfInvalidFileIndexes) {
const uint32_t ThreadCount = 1;
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
OS.flush();
SmallString<512> Str;
raw_svector_ostream OutStrm(Str);
const auto ByteOrder = llvm::endianness::native;
Expand Down Expand Up @@ -4857,7 +4852,6 @@ TEST(GSYMTest, TestLookupsOfOverlappingAndUnequalRanges) {
const uint32_t ThreadCount = 1;
ASSERT_THAT_ERROR(DT.convert(ThreadCount, OSAgg), Succeeded());
ASSERT_THAT_ERROR(GC.finalize(OSAgg), Succeeded());
OS.flush();
SmallString<512> Str;
raw_svector_ostream OutStrm(Str);
const auto ByteOrder = llvm::endianness::native;
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/IR/ConstantsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ TEST(ConstantsTest, PointerCast) {
Instruction *__I = cast<ConstantExpr>(x)->getAsInstruction(); \
__I->print(__o); \
__I->deleteValue(); \
__o.flush(); \
EXPECT_EQ(std::string(" <badref> = " y), __s); \
}

Expand Down
2 changes: 0 additions & 2 deletions llvm/unittests/IR/ManglerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ static std::string mangleStr(StringRef IRName, Mangler &Mang,
std::string Mangled;
raw_string_ostream SS(Mangled);
Mang.getNameWithPrefix(SS, IRName, DL);
SS.flush();
return Mangled;
}

Expand All @@ -37,7 +36,6 @@ static std::string mangleFunc(StringRef IRName,
std::string Mangled;
raw_string_ostream SS(Mangled);
Mang.getNameWithPrefix(SS, F, false);
SS.flush();
F->eraseFromParent();
return Mangled;
}
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/IR/MetadataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ TEST_F(MDNodeTest, Print) {
std::string Actual_; \
raw_string_ostream OS(Actual_); \
PRINT; \
OS.flush(); \
std::string Expected_(EXPECTED); \
EXPECT_EQ(Expected_, Actual_); \
} while (false)
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/IR/ModuleSummaryIndexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ TEST(ModuleSummaryIndexTest, MemProfSummaryPrinting) {
for (auto &AI : AllocSummary->allocs())
OS << "\n" << AI;

OS.flush();
EXPECT_EQ(Data, R"(
Callee: 23 Clones: 0 StackIds: 2, 3
Callee: 23 Clones: 0 StackIds: 2, 4
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/MC/MCInstPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class MCInstPrinterTest : public ::testing::Test {
std::string Buffer;
raw_string_ostream OS(Buffer);
OS << Printer->formatHex(i);
OS.flush();
return Buffer;
}
};
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/MIR/MachineMetadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ static std::string print(std::function<void(raw_ostream &OS)> PrintFn) {
std::string Str;
raw_string_ostream OS(Str);
PrintFn(OS);
OS.flush();
return Str;
}

Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/Object/SymbolicFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ TEST(Object, DataRefImplOstream) {
}

OS << Data;
OS.flush();

EXPECT_EQ(Expected, s);
}
1 change: 0 additions & 1 deletion llvm/unittests/ProfileData/InstrProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,6 @@ MATCHER_P(EqualsRecord, Want, "") {
Want.print(OS);
OS << "Got:\n";
Got.print(OS);
OS.flush();
*result_listener << "MemProf Record differs!\n" << Buffer;
return false;
};
Expand Down
4 changes: 0 additions & 4 deletions llvm/unittests/ProfileData/MemProfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ TEST(MemProf, PortableWrapper) {
std::string Buffer;
llvm::raw_string_ostream OS(Buffer);
WriteBlock.serialize(Schema, OS);
OS.flush();

PortableMemInfoBlock ReadBlock(
Schema, reinterpret_cast<const unsigned char *>(Buffer.data()));
Expand Down Expand Up @@ -296,7 +295,6 @@ TEST(MemProf, RecordSerializationRoundTripVersion0And1) {
std::string Buffer;
llvm::raw_string_ostream OS(Buffer);
Record.serialize(Schema, OS, llvm::memprof::Version0);
OS.flush();

const IndexedMemProfRecord GotRecord = IndexedMemProfRecord::deserialize(
Schema, reinterpret_cast<const unsigned char *>(Buffer.data()),
Expand Down Expand Up @@ -326,7 +324,6 @@ TEST(MemProf, RecordSerializationRoundTripVerion2) {
std::string Buffer;
llvm::raw_string_ostream OS(Buffer);
Record.serialize(Schema, OS, llvm::memprof::Version2);
OS.flush();

const IndexedMemProfRecord GotRecord = IndexedMemProfRecord::deserialize(
Schema, reinterpret_cast<const unsigned char *>(Buffer.data()),
Expand Down Expand Up @@ -378,7 +375,6 @@ TEST(MemProf, RecordSerializationRoundTripVersion2HotColdSchema) {
std::string Buffer;
llvm::raw_string_ostream OS(Buffer);
Record.serialize(Schema, OS, llvm::memprof::Version2);
OS.flush();

const IndexedMemProfRecord GotRecord = IndexedMemProfRecord::deserialize(
Schema, reinterpret_cast<const unsigned char *>(Buffer.data()),
Expand Down
29 changes: 9 additions & 20 deletions llvm/unittests/Support/CommandLineTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,6 @@ TEST(CommandLineTest, LookupFailsInWrongSubCommand) {

const char *args[] = {"prog", "sc1", "-sc2"};
EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, StringRef(), &OS));
OS.flush();
EXPECT_FALSE(Errs.empty());
}

Expand Down Expand Up @@ -616,7 +615,6 @@ TEST(CommandLineTest, AddToAllSubCommands) {
EXPECT_TRUE(AllOpt);

// Since all parsing succeeded, the error message should be empty.
OS.flush();
EXPECT_TRUE(Errs.empty());
}

Expand Down Expand Up @@ -657,14 +655,12 @@ TEST(CommandLineTest, RemoveFromRegularSubCommand) {
EXPECT_FALSE(RemoveOption);
EXPECT_TRUE(cl::ParseCommandLineOptions(3, args, StringRef(), &OS));
EXPECT_TRUE(RemoveOption);
OS.flush();
EXPECT_TRUE(Errs.empty());

RemoveOption.removeArgument();

cl::ResetAllOptionOccurrences();
EXPECT_FALSE(cl::ParseCommandLineOptions(3, args, StringRef(), &OS));
OS.flush();
EXPECT_FALSE(Errs.empty());
}

Expand Down Expand Up @@ -1277,15 +1273,15 @@ TEST(CommandLineTest, PositionalEatArgsError) {

std::string Errs;
raw_string_ostream OS(Errs);
EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS)); OS.flush();
EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS));
EXPECT_FALSE(Errs.empty()); Errs.clear();
EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), &OS)); OS.flush();
EXPECT_FALSE(cl::ParseCommandLineOptions(3, args2, StringRef(), &OS));
EXPECT_FALSE(Errs.empty()); Errs.clear();
EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), &OS)); OS.flush();
EXPECT_TRUE(cl::ParseCommandLineOptions(3, args3, StringRef(), &OS));
EXPECT_TRUE(Errs.empty()); Errs.clear();

cl::ResetAllOptionOccurrences();
EXPECT_TRUE(cl::ParseCommandLineOptions(6, args4, StringRef(), &OS)); OS.flush();
EXPECT_TRUE(cl::ParseCommandLineOptions(6, args4, StringRef(), &OS));
EXPECT_EQ(PosEatArgs.size(), 1u);
EXPECT_EQ(PosEatArgs2.size(), 2u);
EXPECT_TRUE(Errs.empty());
Expand Down Expand Up @@ -1875,15 +1871,15 @@ TEST(CommandLineTest, LongOptions) {
//

EXPECT_TRUE(
cl::ParseCommandLineOptions(4, args1, StringRef(), &OS)); OS.flush();
cl::ParseCommandLineOptions(4, args1, StringRef(), &OS));
EXPECT_TRUE(OptA);
EXPECT_FALSE(OptBLong);
EXPECT_STREQ("val1", OptAB.c_str());
EXPECT_TRUE(Errs.empty()); Errs.clear();
cl::ResetAllOptionOccurrences();

EXPECT_TRUE(
cl::ParseCommandLineOptions(4, args2, StringRef(), &OS)); OS.flush();
cl::ParseCommandLineOptions(4, args2, StringRef(), &OS));
EXPECT_TRUE(OptA);
EXPECT_FALSE(OptBLong);
EXPECT_STREQ("val1", OptAB.c_str());
Expand All @@ -1893,7 +1889,7 @@ TEST(CommandLineTest, LongOptions) {
// Fails because `-ab` and `--ab` are treated the same and appear more than
// once. Also, `val1` is unexpected.
EXPECT_FALSE(
cl::ParseCommandLineOptions(4, args3, StringRef(), &OS)); OS.flush();
cl::ParseCommandLineOptions(4, args3, StringRef(), &OS));
outs()<< Errs << "\n";
EXPECT_FALSE(Errs.empty()); Errs.clear();
cl::ResetAllOptionOccurrences();
Expand All @@ -1906,13 +1902,13 @@ TEST(CommandLineTest, LongOptions) {
// Fails because `-ab` is treated as `-a -b`, so `-a` is seen twice, and
// `val1` is unexpected.
EXPECT_FALSE(cl::ParseCommandLineOptions(4, args1, StringRef(),
&OS, nullptr, true)); OS.flush();
&OS, nullptr, true));
EXPECT_FALSE(Errs.empty()); Errs.clear();
cl::ResetAllOptionOccurrences();

// Works because `-a` is treated differently than `--ab`.
EXPECT_TRUE(cl::ParseCommandLineOptions(4, args2, StringRef(),
&OS, nullptr, true)); OS.flush();
&OS, nullptr, true));
EXPECT_TRUE(Errs.empty()); Errs.clear();
cl::ResetAllOptionOccurrences();

Expand All @@ -1922,7 +1918,6 @@ TEST(CommandLineTest, LongOptions) {
EXPECT_TRUE(OptA);
EXPECT_TRUE(OptBLong);
EXPECT_STREQ("val1", OptAB.c_str());
OS.flush();
EXPECT_TRUE(Errs.empty()); Errs.clear();
cl::ResetAllOptionOccurrences();
}
Expand All @@ -1941,12 +1936,10 @@ TEST(CommandLineTest, OptionErrorMessage) {
raw_string_ostream OS(Errs);

OptA.error("custom error", OS);
OS.flush();
EXPECT_NE(Errs.find("for the -a option:"), std::string::npos);
Errs.clear();

OptLong.error("custom error", OS);
OS.flush();
EXPECT_NE(Errs.find("for the --long option:"), std::string::npos);
Errs.clear();

Expand All @@ -1969,7 +1962,6 @@ TEST(CommandLineTest, OptionErrorMessageSuggest) {
raw_string_ostream OS(Errs);

EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS));
OS.flush();
EXPECT_NE(Errs.find("prog: Did you mean '--aluminium'?\n"),
std::string::npos);
Errs.clear();
Expand All @@ -1992,7 +1984,6 @@ TEST(CommandLineTest, OptionErrorMessageSuggestNoHidden) {
raw_string_ostream OS(Errs);

EXPECT_FALSE(cl::ParseCommandLineOptions(2, args, StringRef(), &OS));
OS.flush();
EXPECT_NE(Errs.find("prog: Did you mean '--aluminium'?\n"),
std::string::npos);
Errs.clear();
Expand Down Expand Up @@ -2082,7 +2073,6 @@ TEST(CommandLineTest, ConsumeAfterOnePositional) {
std::string Errs;
raw_string_ostream OS(Errs);
EXPECT_TRUE(cl::ParseCommandLineOptions(4, Args, StringRef(), &OS));
OS.flush();
EXPECT_EQ("input", Input);
EXPECT_EQ(ExtraArgs.size(), 2u);
EXPECT_EQ(ExtraArgs[0], "arg1");
Expand All @@ -2105,7 +2095,6 @@ TEST(CommandLineTest, ConsumeAfterTwoPositionals) {
std::string Errs;
raw_string_ostream OS(Errs);
EXPECT_TRUE(cl::ParseCommandLineOptions(5, Args, StringRef(), &OS));
OS.flush();
EXPECT_EQ("input1", Input1);
EXPECT_EQ("input2", Input2);
EXPECT_EQ(ExtraArgs.size(), 2u);
Expand Down
3 changes: 1 addition & 2 deletions llvm/unittests/Support/CrashRecoveryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ TEST(CrashRecoveryTest, LimitedStackTrace) {
std::string Res;
llvm::raw_string_ostream RawStream(Res);
PrintStackTrace(RawStream, 1);
std::string Str = RawStream.str();
EXPECT_EQ(std::string::npos, Str.find("#1"));
EXPECT_EQ(std::string::npos, Res.find("#1"));
}

#ifdef _WIN32
Expand Down
2 changes: 0 additions & 2 deletions llvm/unittests/Support/ErrorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,13 +460,11 @@ TEST(Error, createStringError) {
EXPECT_EQ(Msg, "foobar10xff\n")
<< "Unexpected createStringError() log result";

S.flush();
Msg.clear();
logAllUnhandledErrors(createStringError(EC, Bar), S);
EXPECT_EQ(Msg, "bar\n")
<< "Unexpected createStringError() (overloaded) log result";

S.flush();
Msg.clear();
auto Res = errorToErrorCode(createStringError(EC, "foo%s", Bar));
EXPECT_EQ(Res, EC)
Expand Down
1 change: 0 additions & 1 deletion llvm/unittests/Support/FormatVariadicTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ TEST(FormatVariadicTest, BigTest) {
for (auto &Item : Ts) {
Stream << std::apply(format_tuple(Line), Item) << "\n";
}
Stream.flush();
const char *Expected =
R"foo(There are {14} items in the tuple, and {2} tuple(s) in the array.
Char| HexInt| Str | Ref | std::str | double| float| pointer|comma | exp| bigint| bigint2| limit|byte
Expand Down
Loading

0 comments on commit 459a82e

Please sign in to comment.