@Test public void coerceRelativeBuildTarget() throws CoerceFailedException, IOException { SourcePath sourcePath = sourcePathTypeCoercer.coerce( cellRoots, projectFilesystem, pathRelativeToProjectRoot, ":hello"); assertEquals( new BuildTargetSourcePath( BuildTarget.of( UnflavoredBuildTarget.of( projectFilesystem.getRootPath(), Optional.<String>absent(), "//", "hello"), ImmutableSortedSet.<Flavor>of())), sourcePath); }
@Test public void xctoolCommandWithAppAndLogicTests() throws Exception { FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem(); XctoolRunTestsStep step = new XctoolRunTestsStep( projectFilesystem, Paths.get("/path/to/xctool"), Optional.<Long>absent(), "iphonesimulator", Optional.of("name=iPhone 5s,OS=8.2"), ImmutableSet.of(Paths.get("/path/to/FooLogicTest.xctest")), ImmutableMap.of(Paths.get("/path/to/FooAppTest.xctest"), Paths.get("/path/to/Foo.app")), Paths.get("/path/to/output.json"), Optional.<XctoolRunTestsStep.StdoutReadingCallback>absent()); ProcessExecutorParams xctoolParams = ProcessExecutorParams.builder() .setCommand( ImmutableList.of( "/path/to/xctool", "-reporter", "json-stream", "-sdk", "iphonesimulator", "-destination", "name=iPhone 5s,OS=8.2", "run-tests", "-logicTest", "/path/to/FooLogicTest.xctest", "-appTest", "/path/to/FooAppTest.xctest:/path/to/Foo.app")) .setDirectory(projectFilesystem.getRootPath().toAbsolutePath().toFile()) .setRedirectOutput(ProcessBuilder.Redirect.PIPE) .build(); FakeProcess fakeXctoolSuccess = new FakeProcess(0, "", ""); FakeProcessExecutor processExecutor = new FakeProcessExecutor(ImmutableMap.of(xctoolParams, fakeXctoolSuccess)); ExecutionContext executionContext = TestExecutionContext.newBuilder() .setProcessExecutor(processExecutor) .setEnvironment(ImmutableMap.<String, String>of()) .build(); assertThat(step.execute(executionContext), equalTo(0)); }
@Test public void shouldRewriteLineMarkers() { BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); SourcePathResolver pathResolver = new SourcePathResolver(ruleResolver); Path original = Paths.get("buck-out/foo#bar/world.h"); Path finalPath = Paths.get("SANITIZED/world.h"); HeaderPathNormalizer.Builder normalizerBuilder = new HeaderPathNormalizer.Builder(pathResolver, Functions.<Path>identity()); normalizerBuilder.addHeader(new FakeSourcePath("hello/////world.h"), original); HeaderPathNormalizer normalizer = normalizerBuilder.build(); DebugPathSanitizer sanitizer = new DebugPathSanitizer( 9, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("hello"), Paths.get("SANITIZED"))); FakeProjectFilesystem fakeProjectFilesystem = new FakeProjectFilesystem(); CxxPreprocessorOutputTransformerFactory transformer = new CxxPreprocessorOutputTransformerFactory( fakeProjectFilesystem.getRootPath(), normalizer, sanitizer); // Fixup line marker lines properly. assertThat( String.format("# 12 \"%s\"", Escaper.escapePathForCIncludeString(finalPath)), equalTo(transformer.transformLine(String.format("# 12 \"%s\"", original)))); assertThat( String.format("# 12 \"%s\" 2 1", Escaper.escapePathForCIncludeString(finalPath)), equalTo(transformer.transformLine(String.format("# 12 \"%s\" 2 1", original)))); // test.h isn't in the replacement map, so shouldn't be replaced. assertThat("# 4 \"test.h\"", equalTo(transformer.transformLine("# 4 \"test.h\""))); // Don't modify non-line-marker lines. assertThat("int main() {", equalTo(transformer.transformLine("int main() {"))); }