示例#1
0
 @VisibleForTesting
 static boolean isTestRunRequiredForTest(
     TestRule test,
     BuildEngine cachingBuildEngine,
     ExecutionContext executionContext,
     TestRuleKeyFileHelper testRuleKeyFileHelper,
     boolean isResultsCacheEnabled,
     boolean isRunningWithTestSelectors)
     throws IOException, ExecutionException, InterruptedException {
   boolean isTestRunRequired;
   BuildResult result;
   if (executionContext.isDebugEnabled()) {
     // If debug is enabled, then we should always run the tests as the user is expecting to
     // hook up a debugger.
     isTestRunRequired = true;
   } else if (isRunningWithTestSelectors) {
     // As a feature to aid developers, we'll assume that when we are using test selectors,
     // we should always run each test (and never look at the cache.)
     // TODO(user) When #3090004 and #3436849 are closed we can respect the cache again.
     isTestRunRequired = true;
   } else if (((result = cachingBuildEngine.getBuildRuleResult(test.getBuildTarget())) != null)
       && result.getSuccess() == BuildRuleSuccessType.MATCHING_RULE_KEY
       && isResultsCacheEnabled
       && test.hasTestResultFiles(executionContext)
       && testRuleKeyFileHelper.isRuleKeyInDir(test)) {
     // If this build rule's artifacts (which includes the rule's output and its test result
     // files) are up to date, then no commands are necessary to run the tests. The test result
     // files will be read from the XML files in interpretTestResults().
     isTestRunRequired = false;
   } else {
     isTestRunRequired = true;
   }
   return isTestRunRequired;
 }
  @Test
  public void testIsTestRunRequiredIfRuleKeyNotPresent() throws IOException {
    ExecutionContext executionContext = createMock(ExecutionContext.class);
    expect(executionContext.isDebugEnabled()).andReturn(false);

    TestRule testRule = createNiceMock(TestRule.class);
    expect(testRule.getBuildResultType()).andReturn(BuildRuleSuccess.Type.MATCHING_RULE_KEY);
    expect(testRule.hasTestResultFiles(executionContext)).andReturn(true);

    TestRuleKeyFileHelper testRuleKeyFileHelper = createNiceMock(TestRuleKeyFileHelper.class);
    expect(testRuleKeyFileHelper.isRuleKeyInDir(testRule)).andReturn(false);

    replay(executionContext, testRule, testRuleKeyFileHelper);

    assertTrue(
        "A cached build should run the tests if the test output directory\'s rule key is not "
            + "present or does not matche the rule key for the test.",
        TestCommand.isTestRunRequiredForTest(testRule, executionContext, testRuleKeyFileHelper));

    verify(executionContext, testRule, testRuleKeyFileHelper);
  }