Added support to CMake and autoconf for unit tests in clang-tools-extra.
A dummy test exists for now until more meaningful tests can be written.

http://llvm-reviews.chandlerc.com/D605

Files:
  CMakeLists.txt
  Makefile
  test/CMakeLists.txt
  test/Makefile
  test/Unit/lit.cfg
  test/Unit/lit.site.cfg.in
  unittests/CMakeLists.txt
  unittests/Makefile
  unittests/cpp11-migrate/CMakeLists.txt
  unittests/cpp11-migrate/Makefile
  unittests/cpp11-migrate/dummy.cpp
Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -5,3 +5,4 @@
 
 # Add the common testsuite after all the tools.
 add_subdirectory(test)
+add_subdirectory(unittests)
Index: Makefile
===================================================================
--- Makefile
+++ Makefile
@@ -11,7 +11,7 @@
 
 include $(CLANG_LEVEL)/../../Makefile.config
 
-PARALLEL_DIRS := remove-cstr-calls tool-template cpp11-migrate modularize
+PARALLEL_DIRS := remove-cstr-calls tool-template cpp11-migrate modularize unittests
 
 include $(CLANG_LEVEL)/Makefile
 
Index: test/CMakeLists.txt
===================================================================
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -12,6 +12,11 @@
   ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
   )
 
+configure_lit_site_cfg(
+  ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
+  ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg
+  )
+
 option(CLANG_TOOLS_TEST_USE_VG "Run Clang tools' tests under Valgrind" OFF)
 if(CLANG_TOOLS_TEST_USE_VG)
   set(CLANG_TOOLS_TEST_EXTRA_ARGS ${CLANG_TEST_EXTRA_ARGS} "--vg")
@@ -23,6 +28,9 @@
 
   # Individual tools we test.
   remove-cstr-calls cpp11-migrate modularize
+
+  # Unit tests
+  ExtraToolsUnitTests
   )
 
 add_lit_testsuite(check-clang-tools "Running the Clang extra tools' regression tests"
Index: test/Makefile
===================================================================
--- test/Makefile
+++ test/Makefile
@@ -38,15 +38,15 @@
   LIT_ARGS += "--vg"
 endif
 
-all:: lit.site.cfg
+all:: lit.site.cfg Unit/lit.site.cfg
 	@ echo '--- Running the Clang extra tools tests for $(TARGET_TRIPLE) ---'
 	@ $(PYTHON) $(LLVM_SRC_ROOT)/utils/lit/lit.py \
 	  $(LIT_ARGS) $(TESTARGS) $(TESTDIRS)
 
 FORCE:
 
 lit.site.cfg: FORCE
-	@echo "Making Clang extra tools' 'lit.site.cfg' file..."
+	@echo "Making lit.site.cfg for Clang extra tools..."
 	@$(ECHOPATH) s=@LLVM_SOURCE_DIR@=$(LLVM_SRC_ROOT)=g > lit.tmp
 	@$(ECHOPATH) s=@LLVM_BINARY_DIR@=$(LLVM_OBJ_ROOT)=g >> lit.tmp
 	@$(ECHOPATH) s=@LLVM_TOOLS_DIR@=$(ToolDir)=g >> lit.tmp
@@ -57,6 +57,15 @@
 	@sed -f lit.tmp $(PROJ_SRC_DIR)/lit.site.cfg.in > $@
 	@-rm -f lit.tmp
 
+Unit/lit.site.cfg: FORCE
+	@echo "Making Unit/lit.site.cfg for Clang extra tools..."
+	@$(MKDIR) $(dir $@)
+	@$(ECHOPATH) s=@CLANG_TOOLS_BINARY_DIR@=$(PROJ_OBJ_DIR)/..=g >> lit.tmp
+	@$(ECHOPATH) s=@TARGET_TRIPLE@=$(TARGET_TRIPLE)=g >> lit.tmp
+	@$(ECHOPATH) s=@CLANG_TOOLS_SOURCE_DIR@=$(PROJ_SRC_DIR)/..=g >> lit.tmp
+	@sed -f lit.tmp $(PROJ_SRC_DIR)/Unit/lit.site.cfg.in > $@
+	@-rm -f lit.tmp
+
 clean::
 	@ find . -name Output | xargs rm -fr
 
Index: test/Unit/lit.cfg
===================================================================
--- /dev/null
+++ test/Unit/lit.cfg
@@ -0,0 +1,29 @@
+# -*- Python -*-
+
+config.name = "Extra Tools Unit Tests"
+config.suffixes = [] # Seems not to matter for google tests?
+
+# Test Source and Exec root dirs both point to the same directory where google
+# test binaries are built.
+extra_tools_obj_dir = getattr(config, 'extra_tools_obj_dir', None)
+if extra_tools_obj_dir is not None:
+  config.test_source_root = os.path.join(extra_tools_obj_dir, 'unittests')
+  config.test_exec_root = config.test_source_root
+
+# All GoogleTests are named to have 'Tests' as their suffix. The '.' option is
+# a special value for GoogleTest indicating that it should look through the
+# entire testsuite recursively for tests (alternatively, one could provide a
+# ;-separated list of subdirectories).
+config.test_format = lit.formats.GoogleTest('.', 'Tests')
+
+# If the site-specific configuration wasn't loaded (e.g. the build system failed
+# to create it or the user is running a test file directly) try to come up with
+# sane config options.
+if config.test_exec_root is None:
+  # Look for a --param=extra_tools_unit_site_config option.
+  site_cfg = lit.params.get('extra_tools_unit_site_config', None)
+  if site_cfg and os.path.exists(site_cfg):
+      lit.load_config(config, site_cfg)
+      raise SystemExit
+
+  # FIXME: Support out-of-tree builds? See clang/test/Unit/lit.cfg if we care.
Index: test/Unit/lit.site.cfg.in
===================================================================
--- /dev/null
+++ test/Unit/lit.site.cfg.in
@@ -0,0 +1,6 @@
+## Autogenerated by LLVM/Clang configuration.
+# Do not edit!
+config.extra_tools_obj_dir = "@CLANG_TOOLS_BINARY_DIR@"
+config.target_triple = "@TARGET_TRIPLE@"
+
+lit.load_config(config, "@CLANG_TOOLS_SOURCE_DIR@/test/Unit/lit.cfg")
Index: unittests/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_custom_target(ExtraToolsUnitTests)
+set_target_properties(ExtraToolsUnitTests PROPERTIES FOLDER "Extra Tools Unit Tests")
+
+function(add_extra_unittest test_dirname)
+  add_unittest(ExtraToolsUnitTests ${test_dirname} ${ARGN})
+endfunction()
+
+add_subdirectory(cpp11-migrate)
Index: unittests/Makefile
===================================================================
--- /dev/null
+++ unittests/Makefile
@@ -0,0 +1,15 @@
+##===- tools/extra/test/Unit/Makefile ----------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+CLANG_LEVEL := ../../..
+include $(CLANG_LEVEL)/../../Makefile.config
+
+PARALLEL_DIRS := cpp11-migrate
+
+include $(CLANG_LEVEL)/Makefile
Index: unittests/cpp11-migrate/CMakeLists.txt
===================================================================
--- /dev/null
+++ unittests/cpp11-migrate/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  support
+  )
+
+add_extra_unittest(Cpp11MigrateTests
+  dummy.cpp)
+
+target_link_libraries(Cpp11MigrateTests
+  clangTooling
+  clangBasic
+  clangASTMatchers
+  )
+
Index: unittests/cpp11-migrate/Makefile
===================================================================
--- /dev/null
+++ unittests/cpp11-migrate/Makefile
@@ -0,0 +1,22 @@
+##===- unittests/cpp11-migrate/Makefile --------------------*- Makefile -*-===##
+#
+#                     The LLVM Compiler Infrastructure
+#
+# This file is distributed under the University of Illinois Open Source
+# License. See LICENSE.TXT for details.
+#
+##===----------------------------------------------------------------------===##
+
+CLANG_LEVEL = ../../../..
+include $(CLANG_LEVEL)/../../Makefile.config
+
+TESTNAME = Cpp11MigrateTests
+LINK_COMPONENTS := asmparser bitreader support mc
+USEDLIBS = clangTooling.a clangFrontend.a clangSerialization.a clangDriver.a \
+		   clangRewriteFrontend.a clangRewriteCore.a clangParse.a \
+		   clangSema.a clangAnalysis.a \
+		   clangAST.a clangASTMatchers.a clangEdit.a clangLex.a clangBasic.a
+
+include $(CLANG_LEVEL)/Makefile
+MAKEFILE_UNITTEST_NO_INCLUDE_COMMON := 1
+include $(LLVM_SRC_ROOT)/unittests/Makefile.unittest
Index: unittests/cpp11-migrate/dummy.cpp
===================================================================
--- /dev/null
+++ unittests/cpp11-migrate/dummy.cpp
@@ -0,0 +1,6 @@
+#include "gtest/gtest.h"
+
+// FIXME: Replace this test with something more meaningful.
+TEST(SimpleTest, Test) {
+  ASSERT_TRUE(true);
+}
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to