1 //===- unittest/Support/YAMLRemarksSerializerTest.cpp --------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/Remarks/Remark.h"
10 #include "llvm/Remarks/YAMLRemarkSerializer.h"
11 #include "llvm/Support/Error.h"
12 #include "gtest/gtest.h"
16 static void check(const remarks::Remark
&R
, StringRef ExpectedR
,
17 StringRef ExpectedMeta
, bool UseStrTab
= false,
18 Optional
<remarks::StringTable
> StrTab
= None
) {
20 raw_string_ostream
OS(Buf
);
21 Expected
<std::unique_ptr
<remarks::RemarkSerializer
>> MaybeS
= [&] {
24 return createRemarkSerializer(remarks::Format::YAMLStrTab
, OS
,
27 return createRemarkSerializer(remarks::Format::YAMLStrTab
, OS
);
29 return createRemarkSerializer(remarks::Format::YAML
, OS
);
31 EXPECT_FALSE(errorToBool(MaybeS
.takeError()));
32 std::unique_ptr
<remarks::RemarkSerializer
> S
= std::move(*MaybeS
);
35 EXPECT_EQ(OS
.str(), ExpectedR
);
38 std::unique_ptr
<remarks::MetaSerializer
> MS
=
39 S
->metaSerializer(OS
, StringRef("/externalfile"));
41 EXPECT_EQ(OS
.str(), ExpectedMeta
);
44 TEST(YAMLRemarks
, SerializerRemark
) {
46 R
.RemarkType
= remarks::Type::Missed
;
48 R
.RemarkName
= "name";
49 R
.FunctionName
= "func";
50 R
.Loc
= remarks::RemarkLocation
{"path", 3, 4};
52 R
.Args
.emplace_back();
53 R
.Args
.back().Key
= "key";
54 R
.Args
.back().Val
= "value";
55 R
.Args
.emplace_back();
56 R
.Args
.back().Key
= "keydebug";
57 R
.Args
.back().Val
= "valuedebug";
58 R
.Args
.back().Loc
= remarks::RemarkLocation
{"argpath", 6, 7};
63 "DebugLoc: { File: path, Line: 3, Column: 4 }\n"
68 " - keydebug: valuedebug\n"
69 " DebugLoc: { File: argpath, Line: 6, Column: 7 }\n"
78 TEST(YAMLRemarks
, SerializerRemarkStrTab
) {
80 R
.RemarkType
= remarks::Type::Missed
;
82 R
.RemarkName
= "name";
83 R
.FunctionName
= "func";
84 R
.Loc
= remarks::RemarkLocation
{"path", 3, 4};
86 R
.Args
.emplace_back();
87 R
.Args
.back().Key
= "key";
88 R
.Args
.back().Val
= "value";
89 R
.Args
.emplace_back();
90 R
.Args
.back().Key
= "keydebug";
91 R
.Args
.back().Val
= "valuedebug";
92 R
.Args
.back().Loc
= remarks::RemarkLocation
{"argpath", 6, 7};
97 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
103 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
105 StringRef("REMARKS\0"
108 "pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
114 TEST(YAMLRemarks
, SerializerRemarkParsedStrTab
) {
115 StringRef
StrTab("pass\0name\0func\0path\0value\0valuedebug\0argpath\0", 45);
117 R
.RemarkType
= remarks::Type::Missed
;
119 R
.RemarkName
= "name";
120 R
.FunctionName
= "func";
121 R
.Loc
= remarks::RemarkLocation
{"path", 3, 4};
123 R
.Args
.emplace_back();
124 R
.Args
.back().Key
= "key";
125 R
.Args
.back().Val
= "value";
126 R
.Args
.emplace_back();
127 R
.Args
.back().Key
= "keydebug";
128 R
.Args
.back().Val
= "valuedebug";
129 R
.Args
.back().Loc
= remarks::RemarkLocation
{"argpath", 6, 7};
134 "DebugLoc: { File: 3, Line: 3, Column: 4 }\n"
140 " DebugLoc: { File: 6, Line: 6, Column: 7 }\n"
142 StringRef("REMARKS\0"
145 "pass\0name\0func\0path\0value\0valuedebug\0argpath\0"
149 remarks::StringTable(remarks::ParsedStringTable(StrTab
)));