Search in sources :

Example 66 with DefaultTargetNodeToBuildRuleTransformer

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

the class CxxBoostTestTest method testParseResults.

@Test
public void testParseResults() throws Exception {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "boost_test", tmp);
    workspace.setUp();
    ImmutableList<String> samples = ImmutableList.of("simple_success", "simple_failure", "simple_failure_with_output");
    BuildTarget target = BuildTargetFactory.newInstance("//:test");
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    CxxBoostTest test = new CxxBoostTest(new FakeBuildRuleParamsBuilder(target).setProjectFilesystem(new ProjectFilesystem(tmp.getRoot())).build(), ruleFinder, new CxxLink(new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:link")).build(), CxxPlatformUtils.DEFAULT_PLATFORM.getLd().resolve(ruleResolver), Paths.get("output"), ImmutableList.of(), Optional.empty(), /* cacheable */
    true), new CommandTool.Builder().addArg(StringArg.of("")).build(), ImmutableMap.of(), Suppliers.ofInstance(ImmutableList.of()), ImmutableSortedSet.of(), Suppliers.ofInstance(ImmutableSortedSet.of()), ImmutableSet.of(), ImmutableSet.of(), /* runTestSeparately */
    false, /* testRuleTimeoutMs */
    Optional.empty());
    for (String sample : samples) {
        Path exitCode = Paths.get("unused");
        Path output = workspace.resolve(Paths.get(sample)).resolve("output");
        Path results = workspace.resolve(Paths.get(sample)).resolve("results");
        Path summaries = workspace.resolve(Paths.get(sample)).resolve("summaries");
        List<TestResultSummary> expectedSummaries = mapper.readValue(summaries.toFile(), SUMMARIES_REFERENCE);
        ImmutableList<TestResultSummary> actualSummaries = test.parseResults(exitCode, output, results);
        assertEquals(sample, expectedSummaries, actualSummaries);
    }
}
Also used : Path(java.nio.file.Path) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) TestResultSummary(com.facebook.buck.test.TestResultSummary) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) CommandTool(com.facebook.buck.rules.CommandTool) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 67 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer 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 68 with DefaultTargetNodeToBuildRuleTransformer

use of com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer 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 69 with DefaultTargetNodeToBuildRuleTransformer

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

the class TestRunningTest method testMixedSourceFile.

/**
   * If the source paths specified contains one source path to a non-generated file then
   * we should return the correct source tmp corresponding to that non-generated source path.
   * Especially when the generated file comes first in the ordered set.
   */
@Test
public void testMixedSourceFile() throws Exception {
    BuildTarget genSrcTarget = BuildTargetFactory.newInstance("//:gensrc");
    TargetNode<GenruleDescription.Arg, GenruleDescription> sourceGenerator = GenruleBuilder.newGenruleBuilder(genSrcTarget).setOut("com/facebook/GeneratedFile.java").build();
    Path pathToNonGenFile1 = Paths.get("package/src/SourceFile1.java");
    Path pathToNonGenFile2 = Paths.get("package/src-gen/SourceFile2.java");
    BuildTarget javaLibraryTarget = BuildTargetFactory.newInstance("//foo:bar");
    TargetNode<JavaLibraryDescription.Arg, JavaLibraryDescription> javaLibraryNode = JavaLibraryBuilder.createBuilder(javaLibraryTarget).addSrc(pathToNonGenFile1).addSrc(pathToNonGenFile2).addSrcTarget(genSrcTarget).build();
    TargetGraph targetGraph = TargetGraphFactory.newInstance(sourceGenerator, javaLibraryNode);
    BuildRuleResolver ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    JavaLibrary javaLibrary = (JavaLibrary) ruleResolver.requireRule(javaLibraryTarget);
    DefaultJavaPackageFinder defaultJavaPackageFinder = createMock(DefaultJavaPackageFinder.class);
    expect(defaultJavaPackageFinder.getPathsFromRoot()).andReturn(pathsFromRoot).times(2);
    expect(defaultJavaPackageFinder.getPathElements()).andReturn(pathElements).times(2);
    replay(defaultJavaPackageFinder);
    ImmutableSet<String> result = TestRunning.getPathToSourceFolders(javaLibrary, resolver, ruleFinder, defaultJavaPackageFinder);
    Path rootPath = javaLibrary.getProjectFilesystem().getRootPath();
    ImmutableSet<String> expected = ImmutableSet.of(rootPath.resolve("package/src-gen").toString() + "/", rootPath.resolve("package/src").toString() + "/");
    assertEquals("The non-generated source files are under two different source folders.", expected, result);
    verify(defaultJavaPackageFinder);
}
Also used : Path(java.nio.file.Path) GenruleDescription(com.facebook.buck.shell.GenruleDescription) JavaLibraryDescription(com.facebook.buck.jvm.java.JavaLibraryDescription) TargetGraph(com.facebook.buck.rules.TargetGraph) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) DefaultJavaPackageFinder(com.facebook.buck.jvm.java.DefaultJavaPackageFinder) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 70 with DefaultTargetNodeToBuildRuleTransformer

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

the class ArchiveTest method testThatBuildTargetSourcePathDepsAndPathsArePropagated.

@Test
public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    // Create a couple of genrules to generate inputs for an archive rule.
    Genrule genrule1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")).setOut("foo/bar.o").build(resolver);
    Genrule genrule2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")).setOut("foo/test.o").build(resolver);
    // Build the archive using a normal input the outputs of the genrules above.
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    Archive archive = Archive.from(target, params, ruleFinder, DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o"), genrule1.getSourcePathToOutput(), genrule2.getSourcePathToOutput()));
    // Verify that the archive dependencies include the genrules providing the
    // SourcePath inputs.
    assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps());
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) Genrule(com.facebook.buck.shell.Genrule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Aggregations

DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)579 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)578 Test (org.junit.Test)527 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)375 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)352 BuildTarget (com.facebook.buck.model.BuildTarget)257 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)238 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)211 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)204 TargetGraph (com.facebook.buck.rules.TargetGraph)182 BuildRule (com.facebook.buck.rules.BuildRule)161 Path (java.nio.file.Path)115 SourcePath (com.facebook.buck.rules.SourcePath)110 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)101 PathSourcePath (com.facebook.buck.rules.PathSourcePath)90 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)73 RuleKey (com.facebook.buck.rules.RuleKey)70 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)68 AllExistingProjectFilesystem (com.facebook.buck.testutil.AllExistingProjectFilesystem)62 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)49