PageRenderTime 24ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/test/com/facebook/buck/swift/SwiftOSXBinaryIntegrationTest.java

https://gitlab.com/smartether/buck
Java | 201 lines | 163 code | 23 blank | 15 comment | 0 complexity | 1051806e1f200453f00634700231da1a MD5 | raw file
  1. /*
  2. * Copyright 2016-present Facebook, Inc.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  5. * not use this file except in compliance with the License. You may obtain
  6. * a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations
  14. * under the License.
  15. */
  16. package com.facebook.buck.swift;
  17. import static org.hamcrest.Matchers.containsString;
  18. import static org.hamcrest.Matchers.equalTo;
  19. import static org.hamcrest.Matchers.is;
  20. import static org.hamcrest.Matchers.not;
  21. import static org.junit.Assert.assertThat;
  22. import static org.junit.Assume.assumeThat;
  23. import com.facebook.buck.apple.AppleNativeIntegrationTestUtils;
  24. import com.facebook.buck.apple.ApplePlatform;
  25. import com.facebook.buck.cxx.CxxDescriptionEnhancer;
  26. import com.facebook.buck.cxx.CxxPreprocessables;
  27. import com.facebook.buck.cxx.HeaderVisibility;
  28. import com.facebook.buck.io.ProjectFilesystem;
  29. import com.facebook.buck.model.BuildTarget;
  30. import com.facebook.buck.testutil.integration.ProjectWorkspace;
  31. import com.facebook.buck.testutil.integration.TemporaryPaths;
  32. import com.facebook.buck.testutil.integration.TestDataHelper;
  33. import org.junit.Rule;
  34. import org.junit.Test;
  35. import java.io.IOException;
  36. import java.nio.file.Path;
  37. import java.util.Optional;
  38. public class SwiftOSXBinaryIntegrationTest {
  39. @Rule
  40. public TemporaryPaths tmp = new TemporaryPaths(true);
  41. @Test
  42. public void swiftHelloWorldRunsAndPrintsMessageOnOSX() throws IOException {
  43. assumeThat(
  44. AppleNativeIntegrationTestUtils.isSwiftAvailable(ApplePlatform.MACOSX),
  45. is(true));
  46. ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
  47. this,
  48. "helloworld",
  49. tmp);
  50. workspace.setUp();
  51. ProjectWorkspace.ProcessResult runResult = workspace.runBuckCommand(
  52. "run",
  53. ":hello-bin#macosx-x86_64");
  54. runResult.assertSuccess();
  55. assertThat(
  56. runResult.getStdout(),
  57. equalTo("Hello, \uD83C\uDF0E!\n"));
  58. }
  59. @Test
  60. public void changingSourceOfSwiftLibraryDepRelinksBinary() throws IOException {
  61. assumeThat(
  62. AppleNativeIntegrationTestUtils.isSwiftAvailable(ApplePlatform.MACOSX),
  63. is(true));
  64. ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
  65. this,
  66. "helloworld",
  67. tmp);
  68. workspace.setUp();
  69. ProjectWorkspace.ProcessResult runResult = workspace.runBuckCommand(
  70. "run",
  71. ":hello-bin#macosx-x86_64");
  72. runResult.assertSuccess();
  73. assertThat(
  74. runResult.getStdout(),
  75. equalTo("Hello, \uD83C\uDF0E!\n"));
  76. workspace.replaceFileContents("main.swift", "Hello", "Goodbye");
  77. ProjectWorkspace.ProcessResult secondRunResult = workspace.runBuckCommand(
  78. "run",
  79. ":hello-bin#macosx-x86_64");
  80. secondRunResult.assertSuccess();
  81. assertThat(
  82. secondRunResult.getStdout(),
  83. equalTo("Goodbye, \uD83C\uDF0E!\n"));
  84. }
  85. @Test
  86. public void objcMixedSwiftRunsAndPrintsMessageOnOSX() throws IOException {
  87. assumeThat(
  88. AppleNativeIntegrationTestUtils.isSwiftAvailable(ApplePlatform.MACOSX),
  89. is(true));
  90. ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
  91. this, "objc_mix_swift", tmp);
  92. workspace.setUp();
  93. workspace.addBuckConfigLocalOption("swift", "version", "2.3");
  94. ProjectWorkspace.ProcessResult runResult = workspace.runBuckCommand(
  95. "run", ":DemoMix#macosx-x86_64");
  96. runResult.assertSuccess();
  97. assertThat(
  98. runResult.getStdout(),
  99. equalTo("Hello Swift\n"));
  100. }
  101. @Test
  102. public void swiftCallingObjCRunsAndPrintsMessageOnOSX() throws IOException {
  103. assumeThat(
  104. AppleNativeIntegrationTestUtils.isSwiftAvailable(ApplePlatform.MACOSX),
  105. is(true));
  106. ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
  107. this, "swift_calls_objc", tmp);
  108. workspace.setUp();
  109. ProjectWorkspace.ProcessResult runResult = workspace.runBuckCommand(
  110. "run", ":SwiftCallsObjC#macosx-x86_64");
  111. runResult.assertSuccess();
  112. assertThat(
  113. runResult.getStdout(),
  114. containsString("Hello ObjC\n"));
  115. }
  116. @Test
  117. public void testGeneratedModuleWithUmbrellaHeaderFile() throws IOException, InterruptedException {
  118. assumeThat(
  119. AppleNativeIntegrationTestUtils.isSwiftAvailable(ApplePlatform.MACOSX),
  120. is(true));
  121. ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
  122. this, "modules_import", tmp);
  123. workspace.setUp();
  124. ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
  125. BuildTarget target = workspace.newBuildTarget("//:one#macosx-x86_64");
  126. ProjectWorkspace.ProcessResult runResult = workspace.runBuckCommand(
  127. "build",
  128. "--config",
  129. "swift.version=2.3",
  130. target
  131. .withAppendedFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR)
  132. .getFullyQualifiedName());
  133. runResult.assertSuccess();
  134. Path headerMapSymlinkTreePath =
  135. workspace.getPath(
  136. CxxDescriptionEnhancer.getHeaderSymlinkTreePath(
  137. filesystem,
  138. target.withFlavors(),
  139. HeaderVisibility.PUBLIC,
  140. CxxPreprocessables.HeaderMode.SYMLINK_TREE_WITH_HEADER_MAP.getFlavor()));
  141. Path buckModuleMap = headerMapSymlinkTreePath.resolve("buck.modulemap");
  142. Optional<String> fileContent = filesystem.readFileIfItExists(buckModuleMap);
  143. assertThat(fileContent.isPresent(), equalTo(true));
  144. assertThat(fileContent.get(), containsString("umbrella header \"one/one.h\""));
  145. }
  146. @Test
  147. public void testGeneratedModuleWithUmbrellaDirectory() throws IOException, InterruptedException {
  148. assumeThat(
  149. AppleNativeIntegrationTestUtils.isSwiftAvailable(ApplePlatform.MACOSX),
  150. is(true));
  151. ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
  152. this, "modules_import", tmp);
  153. workspace.setUp();
  154. ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
  155. BuildTarget target = workspace.newBuildTarget("//:second-one#macosx-x86_64");
  156. ProjectWorkspace.ProcessResult runResult = workspace.runBuckCommand(
  157. "build",
  158. "--config", "swift.version=2.3",
  159. target
  160. .withAppendedFlavors(CxxDescriptionEnhancer.SHARED_FLAVOR)
  161. .getFullyQualifiedName());
  162. runResult.assertSuccess();
  163. Path headerMapSymlinkTreePath =
  164. workspace.getPath(
  165. CxxDescriptionEnhancer.getHeaderSymlinkTreePath(
  166. filesystem,
  167. target.withFlavors(),
  168. HeaderVisibility.PUBLIC,
  169. CxxPreprocessables.HeaderMode.SYMLINK_TREE_WITH_HEADER_MAP.getFlavor()));
  170. Path buckModuleMap = headerMapSymlinkTreePath.resolve("buck.modulemap");
  171. Optional<String> fileContentOptional = filesystem.readFileIfItExists(buckModuleMap);
  172. assertThat(fileContentOptional.isPresent(), equalTo(true));
  173. String fileContent = fileContentOptional.get();
  174. assertThat(fileContent, containsString("module second_one"));
  175. assertThat(fileContent, not(containsString("module second-one")));
  176. assertThat(fileContent, containsString("umbrella \"second_one\""));
  177. }
  178. }