| /* |
| * Copyright 2012-present Facebook, Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| * not use this file except in compliance with the License. You may obtain |
| * a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package com.facebook.buck.cli; |
| |
| import static org.hamcrest.Matchers.containsString; |
| import static org.hamcrest.Matchers.not; |
| import static org.junit.Assert.assertEquals; |
| import static org.junit.Assert.assertThat; |
| import com.facebook.buck.testutil.integration.DebuggableTemporaryFolder; |
| import com.facebook.buck.testutil.integration.ProjectWorkspace; |
| import com.facebook.buck.testutil.integration.ProjectWorkspace.ProcessResult; |
| import com.facebook.buck.testutil.integration.TestDataHelper; |
| import com.google.common.base.Joiner; |
| |
| import org.junit.Rule; |
| import org.junit.Test; |
| |
| import java.io.IOException; |
| |
| /** |
| * Integration test for the {@code buck project} command. |
| */ |
| public class ProjectIntegrationTest { |
| |
| @Rule |
| public DebuggableTemporaryFolder temporaryFolder = new DebuggableTemporaryFolder(); |
| |
| @Test |
| public void testBuckProject() throws IOException { |
| ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario( |
| this, "project1", temporaryFolder); |
| workspace.setUp(); |
| |
| ProcessResult result = workspace.runBuckCommand("project"); |
| result.assertExitCode("buck project should exit cleanly", 0); |
| |
| workspace.verify(); |
| |
| assertEquals( |
| "`buck project` should report the files it modified.", |
| Joiner.on('\n').join( |
| "MODIFIED FILES:", |
| ".idea/compiler.xml", |
| ".idea/libraries/libs_guava_jar.xml", |
| ".idea/libraries/libs_jsr305_jar.xml", |
| ".idea/libraries/libs_junit_jar.xml", |
| ".idea/modules.xml", |
| ".idea/runConfigurations/Debug_Buck_test.xml", |
| "modules/dep1/module_modules_dep1.iml", |
| "modules/tip/module_modules_tip.iml" |
| ) + '\n', |
| result.getStdout()); |
| |
| assertThat( |
| "`buck project` should contain warning about being run from directory without git.", |
| result.getStderr(), |
| not(containsString(Joiner.on('\n').join( |
| " :: \"buck project\" run from a directory not under Git source", |
| " :: control. If invoking buck project with an argument, we are", |
| " :: not able to remove old .iml files, which can result in", |
| " :: IntelliJ being in a bad state. Please close and re-open", |
| " :: IntelliJ if it's open.")))); |
| } |
| |
| /** |
| * Verify that if we build a project by specifying a target, the resulting project only contains |
| * the transitive deps of that target. In this example, that means everything except |
| * //modules/tip. |
| */ |
| @Test |
| public void testBuckProjectSlice() throws IOException { |
| ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario( |
| this, "project_slice", temporaryFolder); |
| workspace.setUp(); |
| |
| ProcessResult result = workspace.runBuckCommand("project", "//modules/dep1:dep1"); |
| result.assertExitCode("buck project should exit cleanly", 0); |
| |
| workspace.verify(); |
| |
| assertEquals( |
| "`buck project` should report the files it modified.", |
| Joiner.on('\n').join( |
| "MODIFIED FILES:", |
| ".idea/compiler.xml", |
| ".idea/libraries/libs_guava_jar.xml", |
| ".idea/libraries/libs_jsr305_jar.xml", |
| ".idea/libraries/libs_junit_jar.xml", |
| ".idea/modules.xml", |
| ".idea/runConfigurations/Debug_Buck_test.xml", |
| "modules/dep1/module_modules_dep1.iml" |
| ) + '\n', |
| result.getStdout()); |
| |
| assertThat( |
| "`buck project` should contain warning about being run from directory without git.", |
| result.getStderr(), |
| containsString(Joiner.on('\n').join( |
| " :: \"buck project\" run from a directory not under Git source", |
| " :: control. If invoking buck project with an argument, we are", |
| " :: not able to remove old .iml files, which can result in", |
| " :: IntelliJ being in a bad state. Please close and re-open", |
| " :: IntelliJ if it's open."))); |
| } |
| |
| /** |
| * Tests the case where a build file has a test rule that depends on a library rule in the same |
| * build file, and the test rule is specified as the {@code test_target} in its |
| * {@code project_config()}. When this happens, all libraries in the generated {@code .iml} file |
| * should be listed before any of the modules. |
| * <p> |
| * This prevents a regression where JUnit was not being loaded early enough in the classpath, |
| * which led to a "JUnit version 3.8 or later expected" error when running tests in IntelliJ. |
| * (Presumably, IntelliJ ended up loading JUnit 3 from android.jar instead of loading JUnit 4 |
| * from the version of JUnit checked into version control.) |
| */ |
| @Test |
| public void testBuckProjectWithMultipleLibrariesInOneBuildFile() throws IOException { |
| ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario( |
| this, "buck_project_multiple_libraries_in_one_build_file", temporaryFolder); |
| workspace.setUp(); |
| |
| ProcessResult result = workspace.runBuckCommand("project"); |
| result.assertExitCode("buck project should exit cleanly", 0); |
| |
| workspace.verify(); |
| } |
| } |