mirror of
https://github.com/QB64-Phoenix-Edition/QB64pe.git
synced 2024-07-06 21:00:25 +00:00
Add filesys test
This commit is contained in:
parent
941f3583a4
commit
901bdb4cd3
|
@ -769,7 +769,7 @@ void sub_kill(qbs *str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process all matches
|
// Process all matches
|
||||||
while (!IsStringEmpty(entry)) {
|
do {
|
||||||
// We'll delete only if it is a file
|
// We'll delete only if it is a file
|
||||||
if (FileExists(fileName.c_str())) {
|
if (FileExists(fileName.c_str())) {
|
||||||
if (remove(fileName.c_str())) {
|
if (remove(fileName.c_str())) {
|
||||||
|
@ -791,7 +791,7 @@ void sub_kill(qbs *str) {
|
||||||
|
|
||||||
entry = GetDirectoryEntryName(nullptr); // get the next entry
|
entry = GetDirectoryEntryName(nullptr); // get the next entry
|
||||||
filepath_join(fileName, directory, entry);
|
filepath_join(fileName, directory, entry);
|
||||||
}
|
} while (!IsStringEmpty(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief Creates a new directory
|
/// @brief Creates a new directory
|
||||||
|
|
55
tests/compile_tests/filesystem/filesys_test.bas
Normal file
55
tests/compile_tests/filesystem/filesys_test.bas
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
$CONSOLE:ONLY
|
||||||
|
OPTION _EXPLICIT
|
||||||
|
|
||||||
|
CHDIR _STARTDIR$
|
||||||
|
|
||||||
|
PRINT "Creating directory temp_dir"
|
||||||
|
MKDIR "temp_dir"
|
||||||
|
|
||||||
|
PRINT "Changing to directory temp_dir"
|
||||||
|
CHDIR "temp_dir"
|
||||||
|
|
||||||
|
PRINT "Changing to parent directory"
|
||||||
|
CHDIR ".."
|
||||||
|
|
||||||
|
PRINT "Renaming temp_dir to dummy_dir"
|
||||||
|
NAME "temp_dir" AS "dummy_dir"
|
||||||
|
|
||||||
|
PRINT "_DIREXISTS(dummy_dir):"; _DIREXISTS("./dummy_dir")
|
||||||
|
|
||||||
|
PRINT "Creating a temporary file inside dummy_dir"
|
||||||
|
DIM fileName AS STRING: fileName = CreateDummyFile$("./dummy_dir/")
|
||||||
|
|
||||||
|
PRINT "_FILEEXISTS(fileName):"; _FILEEXISTS(fileName)
|
||||||
|
|
||||||
|
PRINT "Deleting fileName"
|
||||||
|
KILL fileName
|
||||||
|
|
||||||
|
PRINT "Creating 10 dummy files inside dummy_dir"
|
||||||
|
DIM i AS LONG: FOR i = 0 TO 9
|
||||||
|
fileName = CreateDummyFile$("./dummy_dir/")
|
||||||
|
NEXT i
|
||||||
|
|
||||||
|
PRINT "Deleting all 10 dummy files"
|
||||||
|
KILL "./dummy_dir/*.tmp"
|
||||||
|
|
||||||
|
PRINT "Deleting dummy_dir"
|
||||||
|
RMDIR "dummy_dir"
|
||||||
|
|
||||||
|
SYSTEM
|
||||||
|
|
||||||
|
FUNCTION CreateDummyFile$ (directory AS STRING)
|
||||||
|
DO
|
||||||
|
DIM fileName AS STRING: fileName = LTRIM$(STR$(100! * (TIMER + RND))) + ".tmp"
|
||||||
|
LOOP WHILE _FILEEXISTS(directory + fileName)
|
||||||
|
|
||||||
|
fileName = directory + fileName
|
||||||
|
|
||||||
|
DIM h AS LONG: h = FREEFILE
|
||||||
|
|
||||||
|
OPEN fileName FOR OUTPUT AS h
|
||||||
|
PRINT #h, "Delete me!"
|
||||||
|
CLOSE h
|
||||||
|
|
||||||
|
CreateDummyFile = fileName
|
||||||
|
END FUNCTION
|
11
tests/compile_tests/filesystem/filesys_test.output
Normal file
11
tests/compile_tests/filesystem/filesys_test.output
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
Creating directory temp_dir
|
||||||
|
Changing to directory temp_dir
|
||||||
|
Changing to parent directory
|
||||||
|
Renaming temp_dir to dummy_dir
|
||||||
|
_DIREXISTS(dummy_dir):-1
|
||||||
|
Creating a temporary file inside dummy_dir
|
||||||
|
_FILEEXISTS(fileName):-1
|
||||||
|
Deleting fileName
|
||||||
|
Creating 10 dummy files inside dummy_dir
|
||||||
|
Deleting all 10 dummy files
|
||||||
|
Deleting dummy_dir
|
Loading…
Reference in a new issue