private void doOverwrite(File resource) { try { String text = FileUtil.loadFile(resource, CharsetToolkit.UTF8); String relativePath = resource.getPath().replace(getTestDataDirectoryPath(), EMPTY_STRING); String actual = printTokens(StringUtil.convertLineSeparators(text.trim()), 0); String pathname = (getExpectedResultDirectoryPath() + relativePath).replace(".bal", "") + ".txt"; File expectedResultFile = new File(pathname); VfsTestUtil.overwriteTestData(expectedResultFile.toString(), actual); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void setUp() throws Exception { super.setUp(); VirtualFile virtualFile = myFixture.copyFileToProject("classes.php"); VfsTestUtil.createDir(virtualFile.getParent(), "Resources/views"); }
private void doOverwrite(File resource) { try { String name = resource.getName().replace("." + myFileExt, EMPTY_STRING); // Retrieves relative path of the file since loadFile() uses "myFullDataPath" as the source root. String relativeFilePath = resource.getPath().replace(getTestDataPath(), EMPTY_STRING); String text = loadFile(relativeFilePath); myFile = createPsiFile(name, text); String psiString = DebugUtil.psiToString(myFile, false, true); String outputFilePath = new File(getExpectedResultPath() + relativeFilePath).toString() .replace("." + myFileExt, ".txt"); VfsTestUtil.overwriteTestData(outputFilePath, psiString); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Check the result against a plain text file. Creates file if missing. * Avoids the default sandboxing in IntelliJ. */ public void doCheckResult(final String fullPath, final String targetDataName, String text) throws IOException { text = text.trim(); final String expectedFileName = fullPath + File.separator + targetDataName; if (OVERWRITE_TESTDATA) { VfsTestUtil.overwriteTestData(expectedFileName, text); System.out.println("File " + expectedFileName + " created."); } try { final String expectedText = doLoadFile(fullPath, targetDataName); if (!Comparing.equal(expectedText, text)) { throw new FileComparisonFailure(targetDataName, expectedText, text, expectedFileName); } } catch (URISyntaxException | IOException e) { VfsTestUtil.overwriteTestData(expectedFileName, text); fail("No output text found. File " + expectedFileName + " created."); } } }