Test that Windows path separators are escaped properly. Add a round-trip
test to verify the JSON produced by the exporter.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@276832
91177308-0d34-0410-b5e6-
96231b3b80d8
// HTML-WHOLE-FILE: <td class='uncovered-line'></td><td class='line-number'><a name='L[[@LINE-44]]'><pre>[[@LINE-44]]</pre></a></td><td class='code'><pre>// after
// HTML-FILTER-NOT: <td class='uncovered-line'></td><td class='line-number'><a name='L[[@LINE-45]]'><pre>[[@LINE-45]]</pre></a></td><td class='code'><pre>// after
-// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -name=main 2>/dev/null | FileCheck %S/Inputs/lineExecutionCounts.json
+// RUN: llvm-cov export %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -name=main 2>/dev/null > %t.export.json
+// RUN: FileCheck -input-file %t.export.json %S/Inputs/lineExecutionCounts.json
+// RUN: cat %t.export.json | %python -c "import json, sys; json.loads(sys.stdin.read())"
void emitSerialized(const int64_t Value) { OS << Value; }
/// \brief Emit a serialized string.
- void emitSerialized(const std::string &Value) { OS << "\"" << Value << "\""; }
+ void emitSerialized(const std::string &Value) {
+ OS << "\"";
+ for (char C : Value) {
+ if (C != '\\')
+ OS << C;
+ else
+ OS << "\\\\";
+ }
+ OS << "\"";
+ }
/// \brief Emit a comma if there is a previous element to delimit.
void emitComma() {
/// \brief Emit a dictionary/object key but no value.
void emitDictKey(const std::string &Key) {
emitComma();
- OS << "\"" << Key << "\":";
+ emitSerialized(Key);
+ OS << ":";
State.pop();
assert((State.size() >= 1) && "Closed too many JSON elements");