From 618d1991351ce4894a82524e2f27ecf00a96c1ab Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Thu, 6 Dec 2012 16:46:10 -0500 Subject: [PATCH] Updated MBS test cases to report when some preconditions fail. --- .../tests/suite/AllManagedBuildTests.java | 3 + .../tests/suite/Preconditions.java | 62 +++++++++++++++++++ .../tests/BuiltinSpecsDetectorTest.java | 14 ++--- 3 files changed, 72 insertions(+), 7 deletions(-) create mode 100644 build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java index 0ae86b7db21..9cdc5e40481 100644 --- a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/AllManagedBuildTests.java @@ -58,6 +58,9 @@ public class AllManagedBuildTests { TestSuite suite = new TestSuite("Test for org.eclipse.cdt.managedbuild.core.tests"); //$JUnit-BEGIN$ + // Preconditions + suite.addTestSuite(Preconditions.class); + // build.core.scannerconfig.tests suite.addTest(CfgScannerConfigProfileManagerTests.suite()); suite.addTestSuite(GCCSpecsConsoleParserTest.class); diff --git a/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java new file mode 100644 index 00000000000..500e6a7981b --- /dev/null +++ b/build/org.eclipse.cdt.managedbuilder.core.tests/suite/org/eclipse/cdt/managedbuilder/tests/suite/Preconditions.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2012,2012 Andrew Gvozdev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Andrew Gvozdev - Initial API and implementation + *******************************************************************************/ + package org.eclipse.cdt.managedbuilder.tests.suite; + +import java.util.Arrays; +import java.util.Set; +import java.util.TreeSet; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.utils.PathUtil; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.core.runtime.content.IContentTypeManager; + +public class Preconditions extends TestCase { + @Override + protected void setUp() throws Exception { + } + + /** + * Many MBS tests run make and gcc and will inspect resulting artifacts of the build. + * Make sure GNU tool-chain is available for the tests. + */ + public void testGnu() { + IPath make = PathUtil.findProgramLocation("make"); + assertNotNull("Precodition FAILED - program 'make' is not found in path.", make); + + IPath gcc = PathUtil.findProgramLocation("gcc"); + assertNotNull("Precodition FAILED - program 'gcc' is not found in path.", gcc); + } + + /** + * Generated makefiles will often contain dependency lines for all file extension + * corresponding content types set in preferences. Make sure that this set has not been + * changed when the tests are run. + */ + public void testContentTypes() { + Set fileExts = new TreeSet(); + IContentTypeManager manager = Platform.getContentTypeManager(); + + IContentType contentTypeCpp = manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE); + fileExts.addAll(Arrays.asList(contentTypeCpp.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); + + IContentType contentTypeC = manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE); + fileExts.addAll(Arrays.asList(contentTypeC.getFileSpecs(IContentType.FILE_EXTENSION_SPEC))); + + Set expectedExts = new TreeSet(Arrays.asList(new String[] {"C", "c", "c++", "cc", "cpp", "cxx"})); + assertEquals("Precodition FAILED - Content Types do not match expected defaults.", expectedExts.toString(), fileExts.toString()); + } + +} 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 5de57531d9d..c10adce4907 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 @@ -51,8 +51,8 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { private static final String PROVIDER_ID = "provider.id"; private static final String PROVIDER_NAME = "provider name"; private static final String LANGUAGE_ID = "language.test.id"; - private static final String CUSTOM_PARAMETER = "customParameter"; - private static final String CUSTOM_PARAMETER_2 = "customParameter2"; + private static final String CUSTOM_COMMAND_1 = "echo 1"; + private static final String CUSTOM_COMMAND_2 = "echo 2"; private static final String ELEM_TEST = "test"; // those attributes must match that in AbstractBuiltinSpecsDetector @@ -203,7 +203,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { List languages = new ArrayList(); languages.add(LANGUAGE_ID); Map properties = new HashMap(); - properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER); + properties.put(ATTR_PARAMETER, CUSTOM_COMMAND_1); List entries = new ArrayList(); ICLanguageSettingEntry entry = new CMacroEntry("MACRO", "VALUE", ICSettingEntry.BUILTIN | ICSettingEntry.READONLY); entries.add(entry); @@ -213,13 +213,13 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { assertEquals(PROVIDER_NAME, provider.getName()); assertEquals(languages, provider.getLanguageScope()); assertEquals(entries, provider.getSettingEntries(null, null, null)); - assertEquals(CUSTOM_PARAMETER, provider.getCommand()); + assertEquals(CUSTOM_COMMAND_1, provider.getCommand()); assertEquals(false, provider.isConsoleEnabled()); assertEquals(false, provider.isExecuted()); // setters - provider.setCommand(CUSTOM_PARAMETER_2); - assertEquals(CUSTOM_PARAMETER_2, provider.getCommand()); + provider.setCommand(CUSTOM_COMMAND_2); + assertEquals(CUSTOM_COMMAND_2, provider.getCommand()); provider.setConsoleEnabled(true); assertEquals(true, provider.isConsoleEnabled()); @@ -259,7 +259,7 @@ public class BuiltinSpecsDetectorTest extends BaseTestCase { // configure provider Map properties = new HashMap(); - properties.put(ATTR_PARAMETER, CUSTOM_PARAMETER); + properties.put(ATTR_PARAMETER, CUSTOM_COMMAND_1); provider.configureProvider(PROVIDER_ID, PROVIDER_NAME, languages, entries, properties); assertEquals(false, provider.isConsoleEnabled()); provider.setConsoleEnabled(true);