From 94e6fe0fa75e1caafa60511a6d615b3af48bb27d Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Fri, 9 Oct 2009 17:43:08 +0000 Subject: [PATCH] bug 212596: JUnit failures in cdt.managedbuilder.test.suite Changes to ignore order in makefile $(RM) command --- .../testplugin/ManagedBuildTestHelper.java | 105 ++++++++++++++++-- .../tests/ManagedProject30MakefileTests.java | 5 +- 2 files changed, 96 insertions(+), 14 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java index 00312da5237..7a2bc38fdd4 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/testplugin/ManagedBuildTestHelper.java @@ -10,6 +10,7 @@ *******************************************************************************/ package org.eclipse.cdt.managedbuilder.testplugin; +import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileReader; @@ -18,7 +19,9 @@ import java.io.IOException; import java.io.InputStream; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.TreeSet; import java.util.zip.ZipFile; import junit.framework.Assert; @@ -375,10 +378,13 @@ public class ManagedBuildTestHelper { */ @Deprecated static public boolean compareBenchmarks(final IProject project, IPath testDir, IPath[] files) { - return compareBenchmarks(project, testDir, files, Path.fromOSString("")); + if (!testDir.isAbsolute()) { + testDir = project.getLocation().append(testDir); + } + return compareBenchmarks(project, testDir, files, project.getLocation()); } - static public boolean compareBenchmarks(final IProject project, IPath testDir, IPath[] files, IPath benchmarkPath) { + static public boolean compareBenchmarks(final IProject project, IPath testLocationBase, IPath[] files, IPath benchmarkLocationBase) { IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRunnable runnable = new IWorkspaceRunnable() { public void run(IProgressMonitor monitor) throws CoreException { @@ -392,13 +398,18 @@ public class ManagedBuildTestHelper { Assert.fail("File " + files[0].lastSegment() + " - project refresh failed."); } for (int i=0; i>>>>>>>>>>>>>>start diff: \n"); - String location1 = benchmarkFile.isAbsolute() - ? benchmarkFile.toString() - : getFileLocation(project, benchmarkFile); - String location2 = getFileLocation(project, testFile); + String location1 = benchmarkFileLocation.isAbsolute() + ? benchmarkFileLocation.toString() + : getFileLocation(project, benchmarkFileLocation); + String location2 = testFileLocation.isAbsolute() + ? testFileLocation.toString() + : getFileLocation(project, testFileLocation); String diff = DiffUtil.getInstance().diff(location1, location2); if(diff == null) diff = "!diff failed!"; @@ -424,6 +437,68 @@ public class ManagedBuildTestHelper { return true; } + private static boolean isMakefile(IPath file) { + String ext = file.getFileExtension(); + if (ext==null) { + String name = file.lastSegment(); + return name!=null && ( + name.equals("makefile") + || name.equals("Makefile") + || name.equals("GNUmakefile") + ); + } + return ext.equals("mk"); + } + + private static boolean compareMakefiles(IPath testFile, IPath benchmarkFile) { + ArrayList testArray = getContents(testFile); + ArrayList benchmarkArray = getContents(benchmarkFile); + if (testArray.size()!=benchmarkArray.size()) + return false; + + for (int i=0;i(Arrays.asList(testLine.split(DELIMITERS))).toArray(new String[0]); + String[] benchMacros = new TreeSet(Arrays.asList(benchmarkLine.split(DELIMITERS))).toArray(new String[0]); + if (testMacros.length!=benchMacros.length) { + return false; + } + for (int j=0;j getContents(IPath fullPath) { + ArrayList lines = new ArrayList(); + try { + BufferedReader in = new BufferedReader(new FileReader(fullPath.toFile())); + String line; + do { + line = in.readLine(); + if (line!=null) { + lines.add(line); + } + } while (line !=null); + } catch (IOException e) { + Assert.fail("File " + fullPath.toString() + " could not be read: " + e.getLocalizedMessage()); + } + return lines; + } + static public boolean compareBenchmarks(final IProject project, IPath testDir, String[] fileNames) { return compareBenchmarks(project, testDir, new Path("benchmarks").append(testDir), fileNames); } @@ -465,6 +540,13 @@ public class ManagedBuildTestHelper { } static public boolean compareBenchmarks(IFile tFile, IFile bmFile) { + IPath tFileLocation = new Path(tFile.toString()); + IPath bmFileLocation = new Path(bmFile.toString()); + if (isMakefile(tFileLocation)) { + if (compareMakefiles(tFileLocation, bmFileLocation)) { + return true; + } + } StringBuffer testBuffer = readContentsStripLineEnds(tFile); StringBuffer benchmarkBuffer = readContentsStripLineEnds(bmFile); if (!testBuffer.toString().equals(benchmarkBuffer.toString())) { @@ -538,7 +620,6 @@ public class ManagedBuildTestHelper { input = new FileReader(fullPath.toFile()); } catch (Exception e) { Assert.fail("File " + fullPath.toString() + " could not be read: " + e.getLocalizedMessage()); - return null; } //InputStream input = file.getContents(true); // A different way to read the file... int c; diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java index 63568f103e5..897435c2726 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/tests/org/eclipse/cdt/managedbuilder/core/tests/ManagedProject30MakefileTests.java @@ -193,8 +193,9 @@ public class ManagedProject30MakefileTests extends TestCase { String configName = info.getDefaultConfiguration().getName(); IPath buildDir = Path.fromOSString(configName); if (compareBenchmark) { - IPath benchmarkPath = resourcesLocation.append(curProject.getName()); - succeeded = ManagedBuildTestHelper.compareBenchmarks(curProject, buildDir, files, benchmarkPath); + IPath benchmarkLocationBase = resourcesLocation.append(curProject.getName()); + IPath buildLocation = curProject.getLocation().append(buildDir); + succeeded = ManagedBuildTestHelper.compareBenchmarks(curProject, buildLocation, files, benchmarkLocationBase); } else { succeeded = ManagedBuildTestHelper.verifyFilesDoNotExist(curProject, buildDir, files); }