From 7d367052156f8e6cbf415ba909862d3fde628577 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 11 Jan 2011 22:13:31 -0800 Subject: [PATCH] Ship unresolved unit test information to Differential. Summary: Test Plan: Reviewers: CC: --- src/__phutil_library_map__.php | 2 + .../PhutilUnitTestEngineTestCase.php | 29 ++++++++++++ src/unit/engine/phutil/__tests__/__init__.php | 12 +++++ src/workflow/diff/ArcanistDiffWorkflow.php | 46 +++++++++++++++---- src/workflow/unit/ArcanistUnitWorkflow.php | 14 ++++-- 5 files changed, 92 insertions(+), 11 deletions(-) create mode 100644 src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php create mode 100644 src/unit/engine/phutil/__tests__/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index e8184561..4811d8c6 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -63,6 +63,7 @@ phutil_register_library_map(array( 'PhutilLintEngine' => 'lint/engine/phutil', 'PhutilModuleRequirements' => 'staticanalysis/parsers/phutilmodule', 'PhutilUnitTestEngine' => 'unit/engine/phutil', + 'PhutilUnitTestEngineTestCase' => 'unit/engine/phutil/__tests__', 'UnitTestableArcanistLintEngine' => 'lint/engine/test', ), 'function' => @@ -98,6 +99,7 @@ phutil_register_library_map(array( 'ArcanistXHPASTLinterTestCase' => 'ArcanistPhutilTestCase', 'PhutilLintEngine' => 'ArcanistLintEngine', 'PhutilUnitTestEngine' => 'ArcanistBaseUnitTestEngine', + 'PhutilUnitTestEngineTestCase' => 'ArcanistPhutilTestCase', 'UnitTestableArcanistLintEngine' => 'ArcanistLintEngine', ), 'requires_interface' => diff --git a/src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php b/src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php new file mode 100644 index 00000000..db3af08c --- /dev/null +++ b/src/unit/engine/phutil/__tests__/PhutilUnitTestEngineTestCase.php @@ -0,0 +1,29 @@ +assertEqual(1, 1, 'This test is expected to pass.'); + } + + public function testFail() { + $this->assertEqual(1, 2, 'This test is expected to fail.'); + } + +} diff --git a/src/unit/engine/phutil/__tests__/__init__.php b/src/unit/engine/phutil/__tests__/__init__.php new file mode 100644 index 00000000..8e4ac28c --- /dev/null +++ b/src/unit/engine/phutil/__tests__/__init__.php @@ -0,0 +1,12 @@ +unresolvedTests) { + $data = array(); + foreach ($this->unresolvedTests as $test) { + $data[] = array( + 'name' => $test->getName(), + 'result' => $test->getResult(), + 'userdata' => $test->getUserData(), + ); + } + $conduit->callMethodSynchronous( + 'differential.setdiffproperty', + array( + 'diff_id' => $diff_info['diffid'], + 'name' => 'arc:unit', + 'data' => json_encode($data), + )); + } + if ($this->shouldOnlyCreateDiff()) { echo phutil_console_format( "Created a new Differential diff:\n". @@ -840,16 +861,20 @@ EOTEXT if (!$continue) { throw new ArcanistUserAbortException(); } - $this->unresolvedLint = $lint_workflow->getUnresolvedMessages(); break; case ArcanistLintWorkflow::RESULT_ERRORS: echo phutil_console_format( "** LINT ERRORS ** Lint raised errors!\n"); - throw new ArcanistUsageException( - "Resolve lint errors or run with --nolint."); + $continue = phutil_console_confirm( + "Lint issued unresolved errors! Ignore lint errors?"); + if (!$continue) { + throw new ArcanistUserAbortException(); + } break; } + $this->unresolvedLint = $lint_workflow->getUnresolvedMessages(); + return $lint_result; } catch (ArcanistNoEngineException $ex) { echo "No lint engine configured for this project.\n"; @@ -892,11 +917,16 @@ EOTEXT case ArcanistUnitWorkflow::RESULT_FAIL: echo phutil_console_format( "** UNIT ERRORS ** Unit testing raised errors!\n"); - throw new ArcanistUsageException( - "Resolve unit test errors or run with --nounit."); + $continue = phutil_console_confirm( + "Unit test results include failures! Ignore test failures?"); + if (!$continue) { + throw new ArcanistUserAbortException(); + } break; } + $this->unresolvedTests = $unit_workflow->getUnresolvedTests(); + return $unit_result; } catch (ArcanistNoEngineException $ex) { echo "No unit test engine is configured for this project.\n"; diff --git a/src/workflow/unit/ArcanistUnitWorkflow.php b/src/workflow/unit/ArcanistUnitWorkflow.php index ceedcad7..0424afbf 100644 --- a/src/workflow/unit/ArcanistUnitWorkflow.php +++ b/src/workflow/unit/ArcanistUnitWorkflow.php @@ -23,6 +23,8 @@ class ArcanistUnitWorkflow extends ArcanistBaseWorkflow { const RESULT_FAIL = 2; const RESULT_SKIP = 3; + private $unresolvedTests; + public function getCommandHelp() { return phutil_console_format(<<** UNSOUND **'), ); + $unresolved = array(); foreach ($results as $result) { $result_code = $result->getResult(); echo $status_codes[$result_code].' '.$result->getName()."\n"; if ($result_code != ArcanistUnitTestResult::RESULT_PASS) { echo $result->getUserData()."\n"; + $unresolved[] = $result; } } + $this->unresolvedTests = $unresolved; $overall_result = self::RESULT_OKAY; foreach ($results as $result) { @@ -111,13 +116,16 @@ EOTEXT $result_code == ArcanistUnitTestResult::RESULT_BROKEN) { $overall_result = self::RESULT_FAIL; break; - } - if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) { + } else if ($result_code == ArcanistUnitTestResult::RESULT_UNSOUND) { $overall_result = self::RESULT_UNSOUND; - break; } } return $overall_result; } + + public function getUnresolvedTests() { + return $this->unresolvedTests; + } + }