From e72330fe5a3109b3076232c99cca6d2bb92c8768 Mon Sep 17 00:00:00 2001 From: Liviu Ionescu Date: Tue, 8 Oct 2013 20:45:59 +0300 Subject: [PATCH] Bug 392416: make BuiltinSpecsDetectorTest.java run on non-windows platforms (accept spaces in paths; increase timestamp by 1000ms) Change-Id: I0bf2cef0e31d655310446a6f5321dd938e4c69ad Also-by: Andrew Gvozdev Signed-off-by: Andrew Gvozdev Signed-off-by: Liviu Ionescu Reviewed-on: https://git.eclipse.org/r/17179 --- .../tests/BuiltinSpecsDetectorTest.java | 48 ++++++++++++------- .../tests/GCCBuildCommandParserTest.java | 10 ++-- .../cdt/core/testplugin/ResourceHelper.java | 3 +- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java index 5c3e4e7ab0e..f5b7be2071e 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/BuiltinSpecsDetectorTest.java @@ -49,6 +49,7 @@ import org.eclipse.cdt.managedbuilder.language.settings.providers.AbstractBuilti import org.eclipse.cdt.utils.envvar.StorableEnvironment; import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; @@ -813,15 +814,18 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { * Test running a provider on compiler upgrades. */ public void testAbstractBuiltinSpecsDetector_CompilerUpgrade() throws Exception { + // Create a folder for this test + IPath folder = ResourceHelper.createWorkspaceFolder(getName()); + // Create test "compiler" - java.io.File compiler = new java.io.File("compiler"); + java.io.File compiler = new java.io.File(folder.append("compiler").toOSString()); compiler.createNewFile(); assertTrue(compiler.exists()); String compilerPath = compiler.getAbsolutePath(); // Create provider MockBuiltinSpecsDetectorWithRunCount provider = new MockBuiltinSpecsDetectorWithRunCount(); - provider.setCommand(compilerPath + " arg1"); + provider.setCommand('"' + compilerPath + '"' + " arg1"); // register environment listener on workspace provider.registerListener(null); waitForProviderToFinish(); @@ -833,7 +837,12 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(1, provider.getExecutedCount()); // "Upgrade" the "compiler" - compiler.setLastModified(compiler.lastModified() + 1); + long lastModified = compiler.lastModified(); + // less than 1 sec might be truncated + compiler.setLastModified(lastModified + 1000); + long lastModifiedUpdated = compiler.lastModified(); + assertTrue(lastModifiedUpdated != lastModified); + // Check that an event triggers rerun after upgrade provider.handleEvent(null); @@ -853,19 +862,24 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { return; } + // Create a folder for this test + IPath folder = ResourceHelper.createWorkspaceFolder(getName()); + // Create test "compiler" - java.io.File compiler = new java.io.File("compiler"); + IPath compilerLocation = folder.append("compiler"); + java.io.File compiler = new java.io.File(compilerLocation.toOSString()); compiler.createNewFile(); assertTrue(compiler.exists()); // Create symbolic link to the test compiler - ResourceHelper.createSymbolicLink(new Path("compilerLink"), new Path(compiler.getAbsolutePath())); - java.io.File compilerLink = new java.io.File("compilerLink"); + IPath compilerLinkLocation = folder.append("compilerLink"); + ResourceHelper.createSymbolicLink(compilerLinkLocation, compilerLocation); + java.io.File compilerLink = new java.io.File(compilerLinkLocation.toOSString()); assertTrue(compilerLink.exists()); String compilerLinkPath = compilerLink.getAbsolutePath(); // Create provider MockBuiltinSpecsDetectorWithRunCount provider = new MockBuiltinSpecsDetectorWithRunCount(); - provider.setCommand(compilerLinkPath + " arg1"); + provider.setCommand('"' + compilerLinkPath + '"' + " arg1"); // register environment listener on workspace provider.registerListener(null); waitForProviderToFinish(); @@ -876,8 +890,12 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { waitForProviderToFinish(); assertEquals(1, provider.getExecutedCount()); - // "Upgrade" the "compiler" - compiler.setLastModified(compiler.lastModified() + 1); + // "Upgrade" the "compiler". Note that less than 1 sec might be truncated. + long lastModified = compiler.lastModified(); + // less than 1 sec might be truncated + compiler.setLastModified(lastModified + 1000); + long lastModifiedUpdated = compiler.lastModified(); + assertTrue(lastModifiedUpdated != lastModified); // Check that an event triggers rerun after upgrade provider.handleEvent(null); @@ -892,15 +910,9 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { * Test running a provider after changing the compiler command. */ public void testAbstractBuiltinSpecsDetector_RerunOnCommandArgsChange() throws Exception { - // Create test "compiler" - java.io.File compiler = new java.io.File("compiler"); - compiler.createNewFile(); - assertTrue(compiler.exists()); - String compilerPath = compiler.getAbsolutePath(); - // Create provider MockBuiltinSpecsDetectorWithRunCount provider = new MockBuiltinSpecsDetectorWithRunCount(); - provider.setCommand(compilerPath + " arg1"); + provider.setCommand("compiler arg1"); // register environment listener on workspace provider.registerListener(null); waitForProviderToFinish(); @@ -911,8 +923,8 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { waitForProviderToFinish(); assertEquals(1, provider.getExecutedCount()); - // Change the compiler command - provider.setCommand(compilerPath + " arg2"); + // Change the compiler command argument + provider.setCommand("compiler arg2"); // Check that an event triggers rerun after changing the compiler command provider.handleEvent(null); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java index 6f8224a2ea4..182ecfbd036 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/language/settings/providers/tests/GCCBuildCommandParserTest.java @@ -973,7 +973,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { parser.processLine("gcc " + "-I/path0 " + "-I. " - + file.getLocation().toOSString()); + + '"' + file.getLocation().toOSString() + '"'); parser.shutdown(); // check entries @@ -1004,7 +1004,7 @@ public class GCCBuildCommandParserTest extends BaseTestCase { parser.processLine("gcc " + "-I/path0 " + "-I. " - + file.getLocation().toOSString()); + + '"' + file.getLocation().toOSString() + '"'); parser.shutdown(); // check entries @@ -1772,9 +1772,9 @@ public class GCCBuildCommandParserTest extends BaseTestCase { // parse line parser.startup(cfgDescription, null); parser.processLine("gcc " - + " -I." - + " -Iinclude" - + " " + file.getLocation().toOSString() + + "-I. " + + "-Iinclude " + + '"' + file.getLocation().toOSString() + '"' ); parser.shutdown(); diff --git a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java index b279048b2be..916c31c7384 100644 --- a/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java +++ b/core/org.eclipse.cdt.core.tests/suite/org/eclipse/cdt/core/testplugin/ResourceHelper.java @@ -8,6 +8,7 @@ * Contributors: * Andrew Gvozdev - Initial API and implementation * James Blackburn (Broadcom Corp.) + * Liviu Ionescu - bug 392416 *******************************************************************************/ package org.eclipse.cdt.core.testplugin; @@ -579,7 +580,7 @@ public class ResourceHelper { throw new UnsupportedOperationException("Windows links .lnk are not supported."); } - String command = "ln -s " + realPath.toOSString() + ' ' + linkPath.toOSString(); + String command[] = { "ln", "-s", realPath.toOSString(), linkPath.toOSString()}; Process process = Runtime.getRuntime().exec(command); // Wait for up to 2.5s...