|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2011, 2022 Broadcom Corporation and others. |
| 3 | + * |
| 4 | + * This program and the accompanying materials |
| 5 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 6 | + * which accompanies this distribution, and is available at |
| 7 | + * https://www.eclipse.org/legal/epl-2.0/ |
| 8 | + * |
| 9 | + * SPDX-License-Identifier: EPL-2.0 |
| 10 | + * |
| 11 | + * Contributors: |
| 12 | + * Broadcom Corporation - Bug 303953 test |
| 13 | + * John Dallaway - Initial implementation (derived from bug 303953 test) |
| 14 | + *******************************************************************************/ |
| 15 | +package org.eclipse.cdt.managedbuilder.core.regressions; |
| 16 | + |
| 17 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 18 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 19 | + |
| 20 | +import java.io.ByteArrayInputStream; |
| 21 | + |
| 22 | +import org.eclipse.cdt.managedbuilder.testplugin.AbstractBuilderTest; |
| 23 | +import org.eclipse.core.resources.IBuildConfiguration; |
| 24 | +import org.eclipse.core.resources.IFolder; |
| 25 | +import org.eclipse.core.resources.IProject; |
| 26 | +import org.eclipse.core.resources.IWorkspaceRunnable; |
| 27 | +import org.eclipse.core.resources.IncrementalProjectBuilder; |
| 28 | +import org.eclipse.core.resources.ResourcesPlugin; |
| 29 | +import org.eclipse.core.runtime.CoreException; |
| 30 | +import org.eclipse.core.runtime.IProgressMonitor; |
| 31 | +import org.junit.jupiter.api.Test; |
| 32 | + |
| 33 | +/** |
| 34 | + * Test that removal of a directory containing source file(s) is |
| 35 | + * processed correctly by the default GnuMakefileGenerator. |
| 36 | + */ |
| 37 | +public class Bug_580441Test extends AbstractBuilderTest { |
| 38 | + |
| 39 | + @Test |
| 40 | + public void testBuildAfterPopulatedSourceFolderDelete() throws CoreException { |
| 41 | + setWorkspace("regressions"); |
| 42 | + final IProject app = loadProject("helloworldC"); |
| 43 | + |
| 44 | + // Create additional source file at src/test/test.c |
| 45 | + final IFolder testFolder = app.getFolder("src/test"); |
| 46 | + testFolder.create(false, false, null); |
| 47 | + testFolder.getFile("test.c").create(new ByteArrayInputStream("int test;".getBytes()), false, null); |
| 48 | + |
| 49 | + // Build debug configuration |
| 50 | + setActiveConfigurationByName(app, "Debug"); |
| 51 | + buildConfig(app.getActiveBuildConfig()); |
| 52 | + assertTrue(app.getFile("Debug/src/test/test.o").exists(), "test.o not created"); |
| 53 | + |
| 54 | + // Delete folder containing test.c and build again |
| 55 | + testFolder.delete(false, null); |
| 56 | + buildConfig(app.getActiveBuildConfig()); |
| 57 | + assertFalse(app.getFolder("Debug/src/test").exists(), "test folder not deleted"); |
| 58 | + } |
| 59 | + |
| 60 | + private void buildConfig(IBuildConfiguration config) throws CoreException { |
| 61 | + ResourcesPlugin.getWorkspace().run(new IWorkspaceRunnable() { |
| 62 | + @Override |
| 63 | + public void run(IProgressMonitor monitor) throws CoreException { |
| 64 | + ResourcesPlugin.getWorkspace().build(new IBuildConfiguration[] { config }, |
| 65 | + IncrementalProjectBuilder.INCREMENTAL_BUILD, true, monitor); |
| 66 | + } |
| 67 | + }, null); |
| 68 | + } |
| 69 | + |
| 70 | +} |
0 commit comments