diff --git a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java index 9e7d37f4bc..b46a2b1ba7 100644 --- a/projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java +++ b/projects/core/src/main/java/dan200/computercraft/core/apis/handles/AbstractHandle.java @@ -177,9 +177,9 @@ public Object[] read(Optional countArg) throws LuaException { /** * Read the remainder of the file. * - * @return The file, or {@code null} if at the end of it. + * @return The remaining contents of the file, or {@code null} in the event of an error. * @throws LuaException If the file has been closed. - * @cc.treturn string|nil The remaining contents of the file, or {@code nil} if we are at the end. + * @cc.treturn string|nil The remaining contents of the file, or {@code nil} in the event of an error. * @cc.since 1.80pr1 */ @Nullable diff --git a/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua b/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua index 37d6d5b157..f9fe7aaa66 100644 --- a/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua +++ b/projects/core/src/test/resources/test-rom/spec/apis/fs_spec.lua @@ -200,6 +200,14 @@ describe("The fs library", function() handle.close() end) + it("reading an empty file returns nil", function() + local file = create_test_file "" + + local handle = fs.open(file, mode) + expect(handle.read()):eq(nil) + handle.close() + end) + it("can read a line of text", function() local file = create_test_file "some\nfile\r\ncontents\n\n" @@ -223,6 +231,16 @@ describe("The fs library", function() expect(handle.readLine(true)):eq(nil) handle.close() end) + + it("readAll always returns a string", function() + local contents = "some\nfile\ncontents" + local file = create_test_file "some\nfile\ncontents" + + local handle = fs.open(file, mode) + expect(handle.readAll()):eq(contents) + expect(handle.readAll()):eq("") + handle.close() + end) end describe("reading", function()