@com.intellij.testFramework.Parameterized.Parameters(name = "{0}") public static List<Object[]> params(Class<?> klass) throws Throwable { final LightPlatformCodeInsightTestCase testCase = (LightPlatformCodeInsightTestCase) klass.newInstance(); if (!(testCase instanceof FileBasedTestCaseHelper)) { fail("Parameterized test should implement FileBasedTestCaseHelper"); } try { PathManagerEx.replaceLookupStrategy(klass, com.intellij.testFramework.Parameterized.class); } catch (IllegalArgumentException ignore) { // allow to run out of idea project } final FileBasedTestCaseHelper fileBasedTestCase = (FileBasedTestCaseHelper) testCase; String testDataPath = testCase.getTestDataPath(); File testDir = null; if (fileBasedTestCase instanceof FileBasedTestCaseHelperEx) { testDir = new File( testDataPath, ((FileBasedTestCaseHelperEx) fileBasedTestCase).getRelativeBasePath()); } else { final TestDataPath annotation = klass.getAnnotation(TestDataPath.class); if (annotation == null) { fail( "TestCase should implement com.intellij.testFramework.FileBasedTestCaseHelperEx or be annotated with com.intellij.testFramework.TestDataPath"); } else { final String trimmedRoot = StringUtil.trimStart( StringUtil.trimStart(annotation.value(), "$CONTENT_ROOT"), "$PROJECT_ROOT"); final String lastPathComponent = new File(testDataPath).getName(); final int idx = trimmedRoot.indexOf(lastPathComponent); testDataPath = testDataPath.replace(File.separatorChar, '/') + (idx > 0 ? trimmedRoot.substring(idx + lastPathComponent.length()) : trimmedRoot); testDir = new File(testDataPath); } } final File[] files = testDir.listFiles(); if (files == null) { fail("Test files not found in " + testDir.getPath()); } final List<Object[]> result = new ArrayList<Object[]>(); for (File file : files) { final String fileSuffix = fileBasedTestCase.getFileSuffix(file.getName()); if (fileSuffix != null) { result.add(new Object[] {fileSuffix, testDataPath}); } } return result; }
protected void doRunTest() throws Throwable { LightPlatformCodeInsightTestCase.super.runTest(); }