From 09f5605a6e665db0f109a3e18f290b5b7974e6e0 Mon Sep 17 00:00:00 2001
From: Jules Villard <jul@fb.com>
Date: Tue, 8 Mar 2016 03:27:44 -0800
Subject: [PATCH] move build integration tests to infer/tests/

Summary:public
It's a test, so infer/tests/ is a good place for it. Also, park the expected
outputs all in their own directory. This will help a future diff that changes
the gradle integration test.

Reviewed By: jeremydubreil

Differential Revision: D3019305

fb-gh-sync-id: d3a3ed8
shipit-source-id: d3a3ed8
---
 Makefile.in                                   | 11 ++++---
 .../build_systems}/build_integration_tests.py | 29 ++++++++++---------
 .../expected_outputs}/ant_report.json         |  0
 .../expected_outputs}/buck_report.json        |  0
 .../expected_outputs}/gradle_report.json      |  0
 5 files changed, 21 insertions(+), 19 deletions(-)
 rename {scripts => infer/tests/build_systems}/build_integration_tests.py (84%)
 rename infer/tests/{ => build_systems/expected_outputs}/ant_report.json (100%)
 rename infer/tests/{ => build_systems/expected_outputs}/buck_report.json (100%)
 rename {examples/android_hello => infer/tests/build_systems/expected_outputs}/gradle_report.json (100%)

diff --git a/Makefile.in b/Makefile.in
index af0309891..2586b54aa 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -86,20 +86,20 @@ test_build:
 	$(MAKE) -C $(SRC_DIR) test_build
 
 ocaml_unit_test: $(INFER_ANALYZERS) unit
-	InferUnit
+	$(INFERUNIT_BIN)
 
 buck_test: $(INFER_ANALYZERS)
 	NO_BUCKD=1 buck clean
 	NO_BUCKD=1 buck test $(TARGETS_TO_TEST)
 ifeq (@BUILD_JAVA_ANALYZERS@,yes)
-	NO_BUCKD=1 ./scripts/build_integration_tests.py
+	NO_BUCKD=1 ./infer/tests/build_systems/build_integration_tests.py
 endif
 
 buck_test_xml: $(INFER_ANALYZERS)
 	NO_BUCKD=1 buck clean
 	NO_BUCKD=1 buck test --xml test.xml $(TARGETS_TO_TEST)
 ifeq (@BUILD_JAVA_ANALYZERS@,yes)
-	NO_BUCKD=1 ./scripts/build_integration_tests.py
+	NO_BUCKD=1 ./infer/tests/build_systems/build_integration_tests.py
 endif
 
 inferTraceBugs_test: $(INFER_ANALYZERS)
@@ -136,7 +136,6 @@ ifeq (@BUILD_C_ANALYZERS@,yes)
 endif
 	$(MAKE) -C $(INFER_DIR) clean
 
-.PHONY: all buck_test buck_test_xml build_integration_tests clean clang
+.PHONY: all buck_test buck_test_xml clean clang
 .PHONY: clang_plugin clang_setup inferTraceBugs_test java ocaml_unit_test
-.PHONY: test test_xml test_build
-
+.PHONY: test test_xml test_build unit
diff --git a/scripts/build_integration_tests.py b/infer/tests/build_systems/build_integration_tests.py
similarity index 84%
rename from scripts/build_integration_tests.py
rename to infer/tests/build_systems/build_integration_tests.py
index 619511d7d..bc124300d 100755
--- a/scripts/build_integration_tests.py
+++ b/infer/tests/build_systems/build_integration_tests.py
@@ -19,15 +19,14 @@ import sys
 import tempfile
 import unittest
 
-SCRIPTS_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
+SCRIPT_DIRECTORY = os.path.dirname(os.path.realpath(__file__))
 sys.path.insert(0,
-                os.path.join(SCRIPTS_DIRECTORY,
-                             os.pardir, 'infer', 'lib', 'python'))
+                os.path.join(SCRIPT_DIRECTORY,
+                             os.pardir, os.pardir, 'lib', 'python'))
 
 from inferlib import issues, utils
 
 
-CURRENT_DIR = os.getcwd()
 REPORT_JSON = 'report.json'
 
 INFER_EXECUTABLE = 'infer'
@@ -40,6 +39,7 @@ REPORT_FIELDS = [
     issues.JSON_INDEX_TYPE,
 ]
 
+EXPECTED_OUTPUTS_DIR = os.path.join(SCRIPT_DIRECTORY, 'expected_outputs')
 
 def should_record_tests():
     return RECORD_ENV in os.environ and os.environ[RECORD_ENV] == '1'
@@ -94,7 +94,7 @@ def run_analysis(root, clean_cmd, build_cmd, analyzer):
     json_path = os.path.join(temp_out_dir, REPORT_JSON)
     found_errors = utils.load_json_from_path(json_path)
     shutil.rmtree(temp_out_dir)
-    os.chdir(CURRENT_DIR)
+    os.chdir(SCRIPT_DIRECTORY)
 
     return found_errors
 
@@ -168,13 +168,14 @@ class BuildIntegrationTest(unittest.TestCase):
     def test_ant_integration(self):
         if is_tool_available(['ant', '-version']):
             print('\nRunning Gradle integration test')
-            root = os.path.join(CURRENT_DIR, 'infer', 'tests')
+            root = os.path.join(SCRIPT_DIRECTORY, os.pardir)
             errors = run_analysis(
                 root,
                 ['ant', 'clean'],
                 ['ant', 'compile'],
                 INFER_EXECUTABLE)
-            do_test(errors, os.path.join(root, 'ant_report.json'))
+            original = os.path.join(EXPECTED_OUTPUTS_DIR, 'ant_report.json')
+            do_test(errors, original)
         else:
             print('\nSkipping Ant integration test')
             assert True
@@ -182,13 +183,15 @@ class BuildIntegrationTest(unittest.TestCase):
     def test_gradle_integration(self):
         if is_tool_available(['gradle', '--version']):
             print('\nRunning Gradle integration test')
-            root = os.path.join(CURRENT_DIR, 'examples', 'android_hello')
+            root = os.path.join(SCRIPT_DIRECTORY, os.pardir, os.pardir,
+                                os.pardir, 'examples', 'android_hello')
             errors = run_analysis(
                 root,
                 ['gradle', 'clean'],
                 ['gradle', 'build'],
                 INFER_EXECUTABLE)
-            do_test(errors, os.path.join(root, 'gradle_report.json'))
+            original = os.path.join(EXPECTED_OUTPUTS_DIR, 'gradle_report.json')
+            do_test(errors, original)
         else:
             print('\nSkipping Gradle integration test')
             assert True
@@ -196,15 +199,15 @@ class BuildIntegrationTest(unittest.TestCase):
     def test_buck_integration(self):
         if is_tool_available(['buck', '--version']):
             print('\nRunning Buck integration test')
-            root = CURRENT_DIR
+            root = os.path.join(SCRIPT_DIRECTORY,
+                                os.pardir, os.pardir, os.pardir)
             errors = run_analysis(
                 root,
                 ['buck', 'clean'],
                 ['buck', 'build', 'infer'],
                 INFER_EXECUTABLE)
-            report_path = os.path.join(
-                CURRENT_DIR, 'infer', 'tests', 'buck_report.json')
-            do_test(errors, report_path)
+            original = os.path.join(EXPECTED_OUTPUTS_DIR, 'buck_report.json')
+            do_test(errors, original)
         else:
             print('\nSkipping Buck integration test')
             assert True
diff --git a/infer/tests/ant_report.json b/infer/tests/build_systems/expected_outputs/ant_report.json
similarity index 100%
rename from infer/tests/ant_report.json
rename to infer/tests/build_systems/expected_outputs/ant_report.json
diff --git a/infer/tests/buck_report.json b/infer/tests/build_systems/expected_outputs/buck_report.json
similarity index 100%
rename from infer/tests/buck_report.json
rename to infer/tests/build_systems/expected_outputs/buck_report.json
diff --git a/examples/android_hello/gradle_report.json b/infer/tests/build_systems/expected_outputs/gradle_report.json
similarity index 100%
rename from examples/android_hello/gradle_report.json
rename to infer/tests/build_systems/expected_outputs/gradle_report.json