From 62965e8051552270a5bac144ff5f9b523a520cfd Mon Sep 17 00:00:00 2001 From: Sam Blackshear Date: Thu, 3 Mar 2016 16:34:20 -0800 Subject: [PATCH] adding runner for OCaml unit tests Reviewed By: cristianoc Differential Revision: D2977765 fb-gh-sync-id: abb1b8b shipit-source-id: abb1b8b --- .gitignore | 1 + Makefile.config.in | 1 + Makefile.in | 11 +++++++++-- infer/src/Makefile.in | 32 +++++++++++++++++++++++++------- infer/src/unit/inferunit.ml | 15 +++++++++++++++ 5 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 infer/src/unit/inferunit.ml diff --git a/.gitignore b/.gitignore index 20e10202d..54d75be5b 100644 --- a/.gitignore +++ b/.gitignore @@ -70,6 +70,7 @@ buck-out/ /infer/bin/InferJava /infer/bin/InferLLVM /infer/bin/InferPrint +/infer/bin/InferUnit /infer/bin/Typeprop /infer/src/backend/version.ml /infer/models/java/models/ diff --git a/Makefile.config.in b/Makefile.config.in index 6c0cf0e23..7dd190167 100644 --- a/Makefile.config.in +++ b/Makefile.config.in @@ -35,6 +35,7 @@ INFERANALYZE_BIN = $(BIN_DIR)/InferAnalyze INFERCLANG_BIN = $(BIN_DIR)/InferClang INFERJAVA_BIN = $(BIN_DIR)/InferJava INFERPRINT_BIN = $(BIN_DIR)/InferPrint +INFERUNIT_BIN = $(BIN_DIR)/InferUnit INFER_ANALYZERS= ifeq (@BUILD_C_ANALYZERS@,yes) diff --git a/Makefile.in b/Makefile.in index 75a181721..af0309891 100644 --- a/Makefile.in +++ b/Makefile.in @@ -78,10 +78,16 @@ endif clang: clang_plugin endif +unit: + $(MAKE) -C $(SRC_DIR) unit + test_build: $(MAKE) -C $(SRC_DIR) test_clean $(MAKE) -C $(SRC_DIR) test_build +ocaml_unit_test: $(INFER_ANALYZERS) unit + InferUnit + buck_test: $(INFER_ANALYZERS) NO_BUCKD=1 buck clean NO_BUCKD=1 buck test $(TARGETS_TO_TEST) @@ -118,7 +124,7 @@ endif --only-show > /dev/null @rm -fr __test-infer-out__ -test: buck_test inferTraceBugs_test +test: ocaml_unit_test buck_test inferTraceBugs_test test_xml: buck_test_xml @@ -131,5 +137,6 @@ endif $(MAKE) -C $(INFER_DIR) clean .PHONY: all buck_test buck_test_xml build_integration_tests clean clang -.PHONY: clang_plugin clang_setup inferTraceBugs_test java +.PHONY: clang_plugin clang_setup inferTraceBugs_test java ocaml_unit_test .PHONY: test test_xml test_build + diff --git a/infer/src/Makefile.in b/infer/src/Makefile.in index fe77ccb4a..fadead9b8 100644 --- a/infer/src/Makefile.in +++ b/infer/src/Makefile.in @@ -34,6 +34,7 @@ CLANG_BUILD_DIR = $(BUILD_DIR)/clang LLVM_BUILD_DIR = $(BUILD_DIR)/llvm SCRIPTS_BUILD_DIR = $(BUILD_DIR)/scripts TEST_BUILD_DIR = $(BUILD_DIR)/test +UNIT_BUILD_DIR = $(BUILD_DIR)/unit ANNOT_DIR = $(SRC_DIR)/_build ETC_DIR = $(INFER_DIR)/etc @@ -80,6 +81,12 @@ INFERPRINT_ATDGEN_STUBS = $(addprefix $(INFERPRINT_ATDGEN_STUB_BASE), $(INFERPRI INFERPRINT_MAIN = $(BACKEND_SOURCES)/inferprint +### InferUnit declarations ### + +UNIT_SOURCES = unit + +INFERUNIT_MAIN = $(UNIT_SOURCES)/inferunit + #### Java declarations #### JAVA_OCAMLBUILD_OPTIONS = -pkgs javalib,ptrees,sawja @@ -140,13 +147,13 @@ DEPENDENCIES = $(BACKEND_SOURCES) checkers eradicate facebook/checkers facebook/ OCAMLBUILD = ocamlbuild $(OCAMLBUILD_OPTIONS) -j 0 $(addprefix -I , $(DEPENDENCIES)) -.PHONY: all java clang llvm checkCopyright build_java build_clang build_llvm build_checkCopyright \ - java_annotations clang_annotations llvm_annotations scripts_annotations \ - init version sanitize clean +.PHONY: all java clang llvm unit checkCopyright build_java build_clang build_llvm build_unit \ + build_checkCopyright java_annotations clang_annotations llvm_annotations \ + scripts_annotations init version sanitize clean default: $(INFER_ANALYZERS) -all: java clang llvm checkCopyright +all: java clang llvm checkCopyright unit java: $(INFERJAVA_BIN) @@ -154,6 +161,8 @@ clang: $(INFERCLANG_BIN) $(CLANG_BINIOU_DICT) llvm: $(INFERLLVM_BIN) +unit: $(INFERUNIT_BIN) + checkCopyright: $(CHECKCOPYRIGHT_BIN) build_java: init $(INFERPRINT_ATDGEN_STUBS) @@ -175,12 +184,17 @@ build_checkCopyright: $(OCAMLBUILD) -build-dir $(SCRIPTS_BUILD_DIR) -I $(SCRIPT_SOURCES) \ $(CHECKCOPYRIGHT_MAIN).native +build_unit: + $(OCAMLBUILD) -build-dir $(UNIT_BUILD_DIR) -I $(UNIT_SOURCES) \ + $(INFERUNIT_MAIN).native + byte: init $(INFERPRINT_ATDGEN_STUBS) $(CLANG_ATDGEN_STUBS) $(INFER_CLANG_FCP_MIRRORED_FILES) $(OCAMLBUILD) -build-dir $(TEST_BUILD_DIR) $(JAVA_OCAMLBUILD_OPTIONS) \ $(INFERANALYZE_MAIN).byte \ $(INFERPRINT_MAIN).byte \ $(INFERJAVA_MAIN).byte \ - $(INFERCLANG_MAIN).byte + $(INFERCLANG_MAIN).byte \ + $(INFERUNIT_MAIN).byte test_build: init $(INFERPRINT_ATDGEN_STUBS) $(CLANG_ATDGEN_STUBS) $(INFER_CLANG_FCP_MIRRORED_FILES) $(OCAMLBUILD) -build-dir $(TEST_BUILD_DIR) $(JAVA_OCAMLBUILD_OPTIONS) \ @@ -188,7 +202,8 @@ test_build: init $(INFERPRINT_ATDGEN_STUBS) $(CLANG_ATDGEN_STUBS) $(INFER_CLANG_ $(INFERANALYZE_MAIN).byte \ $(INFERPRINT_MAIN).byte \ $(INFERJAVA_MAIN).byte \ - $(INFERCLANG_MAIN).byte + $(INFERCLANG_MAIN).byte \ + $(INFERUNIT_MAIN).byte ifeq (@ENABLE_OCAML_ANNOT@,yes) java_annotations: build_java @@ -288,6 +303,9 @@ $(INFERCLANG_BIN): build_clang $(INFERLLVM_BIN): build_llvm $(COPY) $(LLVM_BUILD_DIR)/$(INFERLLVM_MAIN).native $(INFERLLVM_BIN) +$(INFERUNIT_BIN): build_unit + $(COPY) $(UNIT_BUILD_DIR)/$(INFERUNIT_MAIN).native $(INFERUNIT_BIN) + $(CHECKCOPYRIGHT_BIN): build_checkCopyright $(COPY) $(SCRIPTS_BUILD_DIR)/$(CHECKCOPYRIGHT_MAIN).native $(CHECKCOPYRIGHT_BIN) @@ -301,7 +319,7 @@ ifeq (@ENABLE_OCAML_ANNOT@,yes) endif $(REMOVE) $(BACKEND_SOURCES)/version.ml $(REMOVE) $(BACKEND_SOURCES)/version.ml.tmp.* - $(REMOVE) $(INFERJAVA_BIN) $(INFERCLANG_BIN) $(INFERLLVM_BIN) + $(REMOVE) $(INFERJAVA_BIN) $(INFERCLANG_BIN) $(INFERLLVM_BIN) $(INFERUNIT_BIN) $(REMOVE) $(CHECKCOPYRIGHT_BIN) $(REMOVE) $(CLANG_ATDGEN_STUBS) $(REMOVE) $(INFER_CLANG_FCP_MIRRORED_FILES) diff --git a/infer/src/unit/inferunit.ml b/infer/src/unit/inferunit.ml new file mode 100644 index 000000000..b414fdbb0 --- /dev/null +++ b/infer/src/unit/inferunit.ml @@ -0,0 +1,15 @@ +(* + * Copyright (c) 2015 - present Facebook, Inc. + * All rights reserved. + * + * This source code is licensed under the BSD style license found in the + * LICENSE file in the root directory of this source tree. An additional grant + * of patent rights can be found in the PATENTS file in the same directory. + *) + +(** module for running OCaml unit tests *) + +module L = Logging + +let () = + L.stdout "All OCaml unit tests passed.@."