[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-16 Thread Julie Hockett via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE344653: [clang-doc] Add unit tests for YAML generation 
(authored by juliehockett, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53084?vs=169751&id=169910#toc

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D53084

Files:
  unittests/clang-doc/CMakeLists.txt
  unittests/clang-doc/YAMLGeneratorTest.cpp

Index: unittests/clang-doc/CMakeLists.txt
===
--- unittests/clang-doc/CMakeLists.txt
+++ unittests/clang-doc/CMakeLists.txt
@@ -15,6 +15,7 @@
   ClangDocTest.cpp
   MergeTest.cpp
   SerializeTest.cpp
+  YAMLGeneratorTest.cpp
   )
 
 target_link_libraries(ClangDocTests
Index: unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- unittests/clang-doc/YAMLGeneratorTest.cpp
+++ unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -0,0 +1,427 @@
+//===-- clang-doc/YAMLGeneratorTest.cpp
+//===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getYAMLGenerator() {
+  auto G = doc::findGeneratorByName("yaml");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(YAMLGeneratorTest, emitNamespaceYAML) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'Namespace'
+Namespace:   
+  - Type:Namespace
+Name:'A'
+ChildNamespaces: 
+  - Type:Namespace
+Name:'ChildNamespace'
+ChildRecords:
+  - Type:Record
+Name:'ChildStruct'
+ChildFunctions:  
+  - USR: ''
+Name:'OneFunction'
+ReturnType:  
+ChildEnums:  
+  - USR: ''
+Name:'OneEnum'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(YAMLGeneratorTest, emitRecordYAML) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>{"test.cpp"});
+  I.Loc.emplace_back(12, llvm::SmallString<16>{"test.cpp"});
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'r'
+Namespace:   
+  - Type:Namespace
+Name:'A'
+DefLocation: 
+  LineNumber:  10
+  Filename:'test.cpp'
+Location:
+  - LineNumber:  12
+Filename:'test.cpp'
+TagType: Class
+Members: 
+  - Type:
+  Name:'int'
+Name:'X'
+Access:  Private
+Parents: 
+  - Type:Record
+Name:'F'
+VirtualParents:  
+  - Type:Record
+Name:'G'
+ChildRecords:
+  - Type:Record
+Name:'ChildStruct'
+ChildFunctions:  
+  - USR: ''
+Name:'OneFunction'
+ReturnType:  
+ChildEnums:  
+  - USR: ''
+Name:'OneEnum'
+...
+)raw";
+  EXP

[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-15 Thread Jake Ehrlich via Phabricator via cfe-commits
jakehehrlich added a comment.

This just seems like a lit test in unit test form, why does this need to use 
unit tests and not lit tests?


https://reviews.llvm.org/D53084



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-15 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett updated this revision to Diff 169751.
juliehockett marked an inline comment as done.

https://reviews.llvm.org/D53084

Files:
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -0,0 +1,427 @@
+//===-- clang-doc/YAMLGeneratorTest.cpp
+//===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getYAMLGenerator() {
+  auto G = doc::findGeneratorByName("yaml");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(YAMLGeneratorTest, emitNamespaceYAML) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'Namespace'
+Namespace:   
+  - Type:Namespace
+Name:'A'
+ChildNamespaces: 
+  - Type:Namespace
+Name:'ChildNamespace'
+ChildRecords:
+  - Type:Record
+Name:'ChildStruct'
+ChildFunctions:  
+  - USR: ''
+Name:'OneFunction'
+ReturnType:  
+ChildEnums:  
+  - USR: ''
+Name:'OneEnum'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(YAMLGeneratorTest, emitRecordYAML) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  R"raw(---
+USR: ''
+Name:'r'
+Namespace:   
+  - Type:Namespace
+Name:'A'
+DefLocation: 
+  LineNumber:  10
+  Filename:'test.cpp'
+Location:
+  - LineNumber:  12
+Filename:'test.cpp'
+TagType: Class
+Members: 
+  - Type:
+  Name:'int'
+Name:'X'
+Access:  Private
+Parents: 
+  - Type:Record
+Name:'F'
+VirtualParents:  
+  - Type:Record
+Name:'G'
+ChildRecords:
+  - Type:Record
+Name:'ChildStruct'
+ChildFunctions:  
+  - USR: ''
+Name:'OneFunction'
+ReturnType:  
+ChildEnums:  
+  - USR: ''
+Name:'OneEnum'
+...
+)raw";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(YAMLGeneratorTest, emitFunctionYAML) {
+  FunctionInfo I;
+  I.Name = "f";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.ReturnType = TypeInfo(EmptySID, "void", InfoType::IT_default);
+  I.Params.emplace_back("int", "P");
+  I.IsMethod = true;
+  I.Parent = Reference(EmptySID, "Parent", InfoType::IT_record);
+

[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-15 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp:45
+  assert(!Err);
+  std::string Expected =
+  "---\n"

Nit: use raw strings here as well, the same here below.


https://reviews.llvm.org/D53084



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D53084: [clang-doc] Add unit tests for YAML

2018-10-10 Thread Julie Hockett via Phabricator via cfe-commits
juliehockett created this revision.
juliehockett added reviewers: leonardchan, jakehehrlich, lebedev.ri.
juliehockett added a project: clang-tools-extra.
Herald added a subscriber: mgorny.

This is part of a move to convert clang-doc's tests to a more maintainable unit 
test framework, with a smaller number of integration tests to maintain and more 
granular failure feedback.


https://reviews.llvm.org/D53084

Files:
  clang-tools-extra/unittests/clang-doc/CMakeLists.txt
  clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp

Index: clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
===
--- /dev/null
+++ clang-tools-extra/unittests/clang-doc/YAMLGeneratorTest.cpp
@@ -0,0 +1,422 @@
+//===-- clang-doc/YAMLGeneratorTest.cpp
+//===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "ClangDocTest.h"
+#include "Generators.h"
+#include "Representation.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace doc {
+
+std::unique_ptr getYAMLGenerator() {
+  auto G = doc::findGeneratorByName("yaml");
+  if (!G)
+return nullptr;
+  return std::move(G.get());
+}
+
+TEST(YAMLGeneratorTest, emitNamespaceYAML) {
+  NamespaceInfo I;
+  I.Name = "Namespace";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.ChildNamespaces.emplace_back(EmptySID, "ChildNamespace",
+ InfoType::IT_namespace);
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  "---\n"
+  "USR: ''\n"
+  "Name:'Namespace'\n"
+  "Namespace:   \n"
+  "  - Type:Namespace\n"
+  "Name:'A'\n"
+  "ChildNamespaces: \n"
+  "  - Type:Namespace\n"
+  "Name:'ChildNamespace'\n"
+  "ChildRecords:\n"
+  "  - Type:Record\n"
+  "Name:'ChildStruct'\n"
+  "ChildFunctions:  \n"
+  "  - USR: ''\n"
+  "Name:'OneFunction'\n"
+  "ReturnType:  \n"
+  "ChildEnums:  \n"
+  "  - USR: ''\n"
+  "Name:'OneEnum'\n"
+  "...\n";
+  EXPECT_EQ(Expected, Actual.str());
+}
+
+TEST(YAMLGeneratorTest, emitRecordYAML) {
+  RecordInfo I;
+  I.Name = "r";
+  I.Namespace.emplace_back(EmptySID, "A", InfoType::IT_namespace);
+
+  I.DefLoc = Location(10, llvm::SmallString<16>("test.cpp"));
+  I.Loc.emplace_back(12, llvm::SmallString<16>("test.cpp"));
+
+  I.Members.emplace_back("int", "X", AccessSpecifier::AS_private);
+  I.TagType = TagTypeKind::TTK_Class;
+  I.Parents.emplace_back(EmptySID, "F", InfoType::IT_record);
+  I.VirtualParents.emplace_back(EmptySID, "G", InfoType::IT_record);
+
+  I.ChildRecords.emplace_back(EmptySID, "ChildStruct", InfoType::IT_record);
+  I.ChildFunctions.emplace_back();
+  I.ChildFunctions.back().Name = "OneFunction";
+  I.ChildEnums.emplace_back();
+  I.ChildEnums.back().Name = "OneEnum";
+
+  auto G = getYAMLGenerator();
+  assert(G);
+  std::string Buffer;
+  llvm::raw_string_ostream Actual(Buffer);
+  auto Err = G->generateDocForInfo(&I, Actual);
+  assert(!Err);
+  std::string Expected =
+  "---\n"
+  "USR: ''\n"
+  "Name:'r'\n"
+  "Namespace:   \n"
+  "  - Type:Namespace\n"
+  "Name:'A'\n"
+  "DefLocation: \n"
+  "  LineNumber:  10\n"
+  "  Filename:'test.cpp'\n"
+  "Location:\n"
+  "  - LineNumber:  12\n"
+  "Filename:'test.cpp'\n"
+  "TagType: Class\n"
+  "Members: \n"
+  "  - Type:\n"
+  "  Name:'int'\n"
+  "Name:'X'\n"
+  "Access:  Private\n"
+  "Parents: \n"
+  "  - Type:Record\n"
+  "Name:'F'\n"
+  "VirtualParents:  \n"
+  "  - Type:Record\n"
+  "Name:'G'\n"
+  "ChildRecords:\n"
+  "  - Type:Record\n"
+  "Name:'ChildStruct'\n"
+  "ChildFunctions:  \n"
+  "  - USR: '0