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);
}
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);
}
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);
}
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);
}
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));
}
Aggregations