Skip to content
Snippets Groups Projects
Commit 648663fe authored by Lukas Stadler's avatar Lukas Stadler
Browse files

Merge pull request #685 in G/fastr from...

Merge pull request #685 in G/fastr from ~FLORIAN.ANGERER_ORACLE.COM/fastr:improvement/save-session to master

* commit '1ea315a4':
  Implemented improvement preventing a previously stored session to be destroyed by TestBuiltin_quit.
parents 90e7f010 1ea315a4
No related branches found
No related tags found
No related merge requests found
......@@ -22,12 +22,46 @@
*/
package com.oracle.truffle.r.test.builtins;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import com.oracle.truffle.r.test.TestBase;
public class TestBuiltin_quit extends TestBase {
private static final Path PATH_RDATA = Paths.get(".RData");
private static final Path PATH_RHISTORY = Paths.get(".Rhistory");
private static final Path PATH_RDATA_BAK = PATH_RDATA.resolveSibling(PATH_RDATA.getFileName() + ".bak");
private static final Path PATH_RHISTORY_BAK = PATH_RHISTORY.resolveSibling(PATH_RHISTORY.getFileName() + ".bak");
/**
* Test case {@link #testQuitEmptyEnv()} possibly destroys previously stored sessions. If so,
* first backup {@code .RData} and {@code .Rhistory}.
*
* @throws IOException
*/
@BeforeClass
public static void backupHistory() throws IOException {
if (Files.exists(PATH_RDATA)) {
move(PATH_RDATA, PATH_RDATA_BAK);
}
if (Files.exists(PATH_RHISTORY)) {
move(PATH_RHISTORY, PATH_RHISTORY_BAK);
}
}
private static void move(Path pathRData, Path dest) throws IOException {
Files.move(pathRData, dest, StandardCopyOption.REPLACE_EXISTING);
}
@Test
public void testQuitErrorSave() {
assertEval("{ quit(\"xx\") }");
......@@ -37,4 +71,30 @@ public class TestBuiltin_quit extends TestBase {
public void testQuitEmptyEnv() {
assertEval("{ quit(\"yes\") }");
}
/**
* Removes temporarily created files {@code .RData} and {@code .Rhistory} and restore backups if
* available.
*
* @throws IOException
*/
@AfterClass
public static void restoreHistory() throws IOException {
// remove any created ".RData" and ".Rhistory" file
if (Files.exists(PATH_RDATA)) {
Files.delete(PATH_RDATA);
}
if (Files.exists(PATH_RHISTORY)) {
Files.delete(PATH_RHISTORY);
}
// restore previously rescued files
if (Files.exists(PATH_RDATA_BAK)) {
move(PATH_RDATA_BAK, PATH_RDATA);
}
if (Files.exists(PATH_RHISTORY_BAK)) {
move(PATH_RHISTORY_BAK, PATH_RHISTORY);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment