mirror of
https://github.com/edwinb/Idris2-boot.git
synced 2024-11-23 20:22:34 +03:00
Fix and test directory code
This commit is contained in:
parent
87c54caa27
commit
dc67515611
@ -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)
|
||||
|
@ -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) {
|
||||
|
@ -37,6 +37,8 @@ int idris2_fileErrno() {
|
||||
return 2;
|
||||
case EACCES:
|
||||
return 3;
|
||||
case EEXIST:
|
||||
return 4;
|
||||
default:
|
||||
return (errno + 5);
|
||||
}
|
||||
|
@ -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
|
||||
|
15
tests/chez/chez017/dir.idr
Normal file
15
tests/chez/chez017/dir.idr
Normal 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
|
||||
|
7
tests/chez/chez017/expected
Normal file
7
tests/chez/chez017/expected
Normal 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
2
tests/chez/chez017/input
Normal file
@ -0,0 +1,2 @@
|
||||
:exec main
|
||||
:q
|
3
tests/chez/chez017/run
Executable file
3
tests/chez/chez017/run
Executable file
@ -0,0 +1,3 @@
|
||||
$1 --no-banner dir.idr < input
|
||||
cat testdir/test.txt
|
||||
rm -rf build testdir
|
Loading…
Reference in New Issue
Block a user