Fix and test directory code

This commit is contained in:
Edwin Brady 2020-05-14 12:40:48 +01:00
parent 87c54caa27
commit dc67515611
8 changed files with 34 additions and 4 deletions

View File

@ -60,7 +60,7 @@ export
changeDir : String -> IO Bool
changeDir dir
= do ok <- primIO (prim_changeDir dir)
pure (ok /= 0)
pure (ok == 0)
export
currentDir : IO (Maybe String)

View File

@ -7,8 +7,9 @@
#include <unistd.h>
char* idris2_currentDirectory() {
char cwd[1024]; // probably ought to deal with the unlikely event of this being too small
return getcwd(cwd, sizeof(cwd)); // freed by RTS
char* cwd = malloc(1024); // probably ought to deal with the unlikely event of this being too small
getcwd(cwd, 1024);
return cwd; // freed by RTS
}
int idris2_changeDir(char* dir) {

View File

@ -37,6 +37,8 @@ int idris2_fileErrno() {
return 2;
case EACCES:
return 3;
case EEXIST:
return 4;
default:
return (errno + 5);
}

View File

@ -98,7 +98,7 @@ chezTests : List String
chezTests
= ["chez001", "chez002", "chez003", "chez004", "chez005", "chez006",
"chez007", "chez008", "chez009", "chez010", "chez011", "chez012",
"chez013", "chez014", "chez015", "chez016", "chez018",
"chez013", "chez014", "chez015", "chez016", "chez017", "chez018",
"reg001"]
ideModeTests : List String

View File

@ -0,0 +1,15 @@
import System.Directory
main : IO ()
main = do Right () <- createDir "testdir"
| Left err => printLn err
Left err <- createDir "testdir"
| _ => printLn "That wasn't supposed to work"
printLn err
ok <- changeDir "nosuchdir"
printLn ok
ok <- changeDir "testdir"
printLn ok
writeFile "test.txt" "hello\n"
printLn !currentDir

View File

@ -0,0 +1,7 @@
File Exists
False
True
Just "/home/edwin/Research/Yaffle/tests/chez/chez017/testdir"
1/1: Building dir (dir.idr)
Main> Main> Bye for now!
hello

2
tests/chez/chez017/input Normal file
View File

@ -0,0 +1,2 @@
:exec main
:q

3
tests/chez/chez017/run Executable file
View File

@ -0,0 +1,3 @@
$1 --no-banner dir.idr < input
cat testdir/test.txt
rm -rf build testdir