Search in sources :

Example 1 with FakeTestRule

use of com.facebook.buck.rules.FakeTestRule in project buck by facebook.

the class TestRunningTest method testRunWhenPreviouslyFailed.

@Test
public void testRunWhenPreviouslyFailed() throws Exception {
    ExecutionContext executionContext = TestExecutionContext.newBuilder().setDebugEnabled(false).build();
    FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of()) {

        @Override
        public boolean hasTestResultFiles() {
            return true;
        }
    };
    TestRuleKeyFileHelper testRuleKeyFileHelper = createNiceMock(TestRuleKeyFileHelper.class);
    expect(testRuleKeyFileHelper.isRuleKeyInDir(testRule)).andReturn(true).times(2);
    CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
    BuildResult result = BuildResult.success(testRule, MATCHING_RULE_KEY, CacheResult.miss());
    expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result).times(2);
    replay(cachingBuildEngine, testRuleKeyFileHelper);
    final TestResults failedTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.FAILURE, 5000, null, null, null, null)))));
    assertTrue("Test will be rerun if it previously failed", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED_IF_PASSED, Callables.<TestResults>returning(failedTestResults), /* running with test selectors */
    false, /* hasEnvironmentOverrides */
    false));
    final TestResults passedTestResults = FakeTestResults.of(ImmutableList.of(new TestCaseSummary("TestCase", ImmutableList.of(new TestResultSummary("TestCaseResult", "passTest", ResultType.SUCCESS, 5000, null, null, null, null)))));
    assertFalse("Test will be not rerun if it previously passed", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, testRuleKeyFileHelper, TestRunningOptions.TestResultCacheMode.ENABLED_IF_PASSED, Callables.<TestResults>returning(passedTestResults), /* running with test selectors */
    false, /* hasEnvironmentOverrides */
    false));
    verify(cachingBuildEngine, testRuleKeyFileHelper);
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) TestCaseSummary(com.facebook.buck.test.TestCaseSummary) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Example 2 with FakeTestRule

use of com.facebook.buck.rules.FakeTestRule in project buck by facebook.

the class TestRunningTest method testIsTestRunRequiredForTestBuiltLocally.

@Test
public void testIsTestRunRequiredForTestBuiltLocally() throws IOException, ExecutionException, InterruptedException {
    ExecutionContext executionContext = TestExecutionContext.newInstance();
    assertFalse(executionContext.isDebugEnabled());
    FakeTestRule testRule = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
    CachingBuildEngine cachingBuildEngine = createMock(CachingBuildEngine.class);
    BuildResult result = BuildResult.success(testRule, BUILT_LOCALLY, CacheResult.miss());
    expect(cachingBuildEngine.getBuildRuleResult(BuildTargetFactory.newInstance("//:lulz"))).andReturn(result);
    replay(cachingBuildEngine);
    assertTrue("A test built locally should always run regardless of any cached result. ", TestRunning.isTestRunRequiredForTest(testRule, cachingBuildEngine, executionContext, createMock(TestRuleKeyFileHelper.class), TestRunningOptions.TestResultCacheMode.ENABLED, Callables.<TestResults>returning(null), /* running with test selectors */
    false, /* hasEnvironmentOverrides */
    false));
    verify(cachingBuildEngine);
}
Also used : BuildResult(com.facebook.buck.rules.BuildResult) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) CachingBuildEngine(com.facebook.buck.rules.CachingBuildEngine) TestResults(com.facebook.buck.test.TestResults) FakeTestResults(com.facebook.buck.test.FakeTestResults) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Example 3 with FakeTestRule

use of com.facebook.buck.rules.FakeTestRule in project buck by facebook.

the class TestCommandTest method testLabelPlingSyntax.

@Test
public void testLabelPlingSyntax() throws CmdLineException {
    TestCommand command = getCommand("--labels", "!c", "a+b");
    TestRule rule = new FakeTestRule(ImmutableSet.of(Label.of("a"), Label.of("b"), Label.of("c")), BuildTargetFactory.newInstance("//:for"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), ImmutableSortedSet.of());
    List<TestRule> testRules = ImmutableList.of(rule);
    Iterable<TestRule> result = command.filterTestRules(FakeBuckConfig.builder().build(), ImmutableSet.of(), testRules);
    assertEquals(ImmutableSet.of(), result);
}
Also used : FakeTestRule(com.facebook.buck.rules.FakeTestRule) TestRule(com.facebook.buck.rules.TestRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Example 4 with FakeTestRule

use of com.facebook.buck.rules.FakeTestRule in project buck by facebook.

the class TestCommandTest method testLabelConjunctionsWithInclude.

@Test
public void testLabelConjunctionsWithInclude() throws CmdLineException {
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    TestCommand command = getCommand("--include", "windows+linux");
    TestRule rule1 = new FakeTestRule(ImmutableSet.of(Label.of("windows"), Label.of("linux")), BuildTargetFactory.newInstance("//:for"), pathResolver, ImmutableSortedSet.of());
    TestRule rule2 = new FakeTestRule(ImmutableSet.of(Label.of("windows")), BuildTargetFactory.newInstance("//:lulz"), pathResolver, ImmutableSortedSet.of());
    List<TestRule> testRules = ImmutableList.of(rule1, rule2);
    Iterable<TestRule> result = command.filterTestRules(FakeBuckConfig.builder().build(), ImmutableSet.of(), testRules);
    assertEquals(ImmutableSet.of(rule1), result);
}
Also used : FakeTestRule(com.facebook.buck.rules.FakeTestRule) TestRule(com.facebook.buck.rules.TestRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Example 5 with FakeTestRule

use of com.facebook.buck.rules.FakeTestRule in project buck by facebook.

the class TestCommandTest method testIncludingATestOnTheCommandLineMeansYouWouldLikeItRun.

@Test
public void testIncludingATestOnTheCommandLineMeansYouWouldLikeItRun() throws CmdLineException {
    String excludedLabel = "exclude_me";
    BuckConfig config = FakeBuckConfig.builder().setSections(ImmutableMap.of("test", ImmutableMap.of("excluded_labels", excludedLabel))).build();
    assertThat(config.getDefaultRawExcludedLabelSelectors(), contains(excludedLabel));
    TestCommand command = new TestCommand();
    new AdditionalOptionsCmdLineParser(command).parseArgument("//example:test");
    FakeTestRule rule = new FakeTestRule(/* labels */
    ImmutableSet.of(Label.of(excludedLabel)), BuildTargetFactory.newInstance("//example:test"), new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()))), /* deps */
    ImmutableSortedSet.of());
    Iterable<TestRule> filtered = command.filterTestRules(config, ImmutableSet.of(BuildTargetFactory.newInstance("//example:test")), ImmutableSet.of(rule));
    assertEquals(rule, Iterables.getOnlyElement(filtered));
}
Also used : FakeTestRule(com.facebook.buck.rules.FakeTestRule) TestRule(com.facebook.buck.rules.TestRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeTestRule(com.facebook.buck.rules.FakeTestRule) Test(org.junit.Test)

Aggregations

BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)16 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)16 FakeTestRule (com.facebook.buck.rules.FakeTestRule)16 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)16 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)16 Test (org.junit.Test)16 TestRule (com.facebook.buck.rules.TestRule)8 ExecutionContext (com.facebook.buck.step.ExecutionContext)8 TestExecutionContext (com.facebook.buck.step.TestExecutionContext)8 FakeTestResults (com.facebook.buck.test.FakeTestResults)8 TestResults (com.facebook.buck.test.TestResults)8 BuildResult (com.facebook.buck.rules.BuildResult)6 CachingBuildEngine (com.facebook.buck.rules.CachingBuildEngine)5 TestCaseSummary (com.facebook.buck.test.TestCaseSummary)4 TestResultSummary (com.facebook.buck.test.TestResultSummary)4 BuildTarget (com.facebook.buck.model.BuildTarget)3 FakeBuildEngine (com.facebook.buck.rules.FakeBuildEngine)3 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)3 RuleKey (com.facebook.buck.rules.RuleKey)3 DefaultStepRunner (com.facebook.buck.step.DefaultStepRunner)3