Skip to content

Commit

Permalink
Make _FILES$ default to "*" filespec if filespec is an empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
a740g committed Jun 2, 2024
1 parent eff5f84 commit cfc271b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/c/libqb/src/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ qbs *func__files(qbs *qbsFileSpec, int32_t passed) {
std::string fileSpec(reinterpret_cast<char *>(qbsFileSpec->chr), qbsFileSpec->len);

if (fileSpec.empty())
fileSpec = "*.*";
fileSpec = "*";

if (FS_DirectoryExists(filepath_fix_directory(fileSpec))) {
directory = fileSpec;
Expand Down
41 changes: 37 additions & 4 deletions tests/compile_tests/filesystem/filesys_test.bas
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ 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/")
DIM fileName AS STRING: fileName = CreateDummyFile("./dummy_dir/", ".tmp")

PRINT "_FILEEXISTS(fileName):"; _FILEEXISTS(fileName)

Expand All @@ -29,9 +29,41 @@ KILL fileName

PRINT "Creating 10 dummy files inside dummy_dir"
DIM i AS LONG: FOR i = 0 TO 9
fileName = CreateDummyFile$("./dummy_dir/")
fileName = CreateDummyFile("./dummy_dir/", ".tmp")
NEXT i

' Start _FILES$ test
CHDIR "dummy_dir"

fileName = CreateDummyFile("./", "")

i = 0
DIM dirEntry AS STRING: dirEntry = _FILES$("") ' should count 13 entries

DO WHILE LEN(dirEntry) > 0
i = i + 1

dirEntry = _FILES$
LOOP

PRINT "Counted"; i; "entries."

i = 0
dirEntry = _FILES$("*.*") ' should count 12 entries

DO WHILE LEN(dirEntry) > 0
i = i + 1

dirEntry = _FILES$
LOOP

PRINT "Counted"; i; "entries."

KILL fileName

CHDIR ".."
' End _FILES$ test

PRINT "Deleting all 10 dummy files"
KILL "./dummy_dir/*.tmp"

Expand All @@ -44,9 +76,10 @@ test_failed:
PRINT "Test failed!"
SYSTEM 1

FUNCTION CreateDummyFile$ (directory AS STRING)

FUNCTION CreateDummyFile$ (directory AS STRING, extension AS STRING)
DO
DIM fileName AS STRING: fileName = directory + LTRIM$(STR$(100! * (TIMER + RND))) + ".tmp"
DIM fileName AS STRING: fileName = directory + LTRIM$(STR$(100! * (TIMER + RND))) + extension
LOOP WHILE _FILEEXISTS(fileName)

DIM h AS LONG: h = FREEFILE
Expand Down
2 changes: 2 additions & 0 deletions tests/compile_tests/filesystem/filesys_test.output
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ Creating a temporary file inside dummy_dir
_FILEEXISTS(fileName):-1
Deleting fileName
Creating 10 dummy files inside dummy_dir
Counted 13 entries.
Counted 12 entries.
Deleting all 10 dummy files
Deleting dummy_dir

0 comments on commit cfc271b

Please sign in to comment.