From 17f3db835ccc08f6339d8326aae4f12c42b7cc20 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 22 Jan 2026 22:15:34 +0100 Subject: [PATCH] - Remove dependency on test tmp library for stdlib compiler tests. #2800 --- lib/std/libc/libc.c3 | 2 +- releasenotes.md | 1 + test/tmp/.gitkeep | 0 test/unit/stdlib/io/file_mmap.c3 | 44 +++++++++++----------- test/unit/stdlib/io/file_read_write_any.c3 | 10 +++-- 5 files changed, 30 insertions(+), 27 deletions(-) delete mode 100644 test/tmp/.gitkeep diff --git a/lib/std/libc/libc.c3 b/lib/std/libc/libc.c3 index 0dd6c14ec..22b551319 100644 --- a/lib/std/libc/libc.c3 +++ b/lib/std/libc/libc.c3 @@ -178,7 +178,7 @@ extern fn CULong strtoul(char* str, char** endptr, CInt base); extern fn usz strxfrm(char* dest, ZString src, usz n); extern fn CInt system(ZString str); extern fn Time_t timegm(Tm* timeptr) @if(!env::WIN32 && !env::NETBSD); -extern fn ZString tmpnam(ZString str); +extern fn ZString tmpnam(char *buffer); extern fn CFile tmpfile(); extern fn CInt ungetc(CInt c, CFile stream); extern fn CInt unsetenv(ZString name) @if(!env::NETBSD); diff --git a/releasenotes.md b/releasenotes.md index 068682c32..eface0d6d 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -108,6 +108,7 @@ - Attrdef eval environment lacked rtype, causing error on invalid args #2797 - $typeof() returns typeinfo, causing errors #2795. - Empty ichar slice + byte concatenation hit an assert. #2789 +- Remove dependency on test tmp library for stdlib compiler tests. #2800 ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/test/tmp/.gitkeep b/test/tmp/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/unit/stdlib/io/file_mmap.c3 b/test/unit/stdlib/io/file_mmap.c3 index 53496d53f..4ceabacb1 100644 --- a/test/unit/stdlib/io/file_mmap.c3 +++ b/test/unit/stdlib/io/file_mmap.c3 @@ -1,21 +1,20 @@ module std::io::file @if(env::LIBC &&& env::POSIX); +import libc; -import std::io; +tlocal char[1024] buf; -fn void write_file(String path, char[] data) +fn String random_name() { - File f = file::open(path, "wb")!!; - defer f.close()!!; - f.write(data)!!; + return libc::tmpnam(&buf).str_view(); } fn void map_read_only() @test { - const String FNAME = "tmp/map_test_ro"; + String fname = random_name(); char[] msg = "Hello, world"; - write_file(FNAME, msg); + file::save(fname, msg)!!; - File f = file::open(FNAME, "rb")!!; + File f = file::open(fname, "rb")!!; defer f.close()!!; FileMmap mapped_file = file::mmap_file(f, 0, 0, vm::VirtualMemoryAccess.READ)!!; @@ -31,12 +30,12 @@ fn void map_read_only() @test fn void map_read_write() @test { - const String FNAME = "tmp/map_test_rw"; + String fname = random_name(); char[4] data = "ABCD"; - write_file(FNAME, data[..]); + file::save(fname, &data)!!; bool shared = true; - File f = file::open(FNAME, "r+")!!; + File f = file::open(fname, "r+")!!; mmap::FileMmap region = file::mmap_file(f, 0, 0, vm::VirtualMemoryAccess.READWRITE, shared)!!; region.bytes()[1] = 'Z'; @@ -44,7 +43,7 @@ fn void map_read_write() @test region.destroy()!!; f.close()!!; - File fr = file::open(FNAME, "r")!!; + File fr = file::open(fname, "r")!!; defer fr.close()!!; char[4] check; fr.read(check[..])!!; @@ -71,37 +70,38 @@ fn void map_with_offset(String fname, usz offset, usz size, char[] reference_msg fn void map_read_only_with_offset_and_size_zero() @test { - const String FNAME = "tmp/map_test_ro_with_offset"; - char[] msg = "Hello, world"; - write_file(FNAME, msg); + String fname = random_name(); + char[] msg = "Hello, world"; + file::save(fname, msg)!!; usz map_size = 0; for (usz i = 0; i < msg.len; i += 1) { - map_with_offset(FNAME, i, map_size, msg); + map_with_offset(fname, i, map_size, msg); } } fn void map_read_only_with_offset() @test { - const String FNAME = "tmp/map_test_ro_with_offset"; + String fname = random_name(); char[] msg = "Hello, world"; - write_file(FNAME, msg); + file::save(fname, msg)!!; usz map_size = 3; for (usz i = 0; i < msg.len - map_size; i++) { - map_with_offset(FNAME, i, map_size, msg); + map_with_offset(fname, i, map_size, msg); } } + fn void map_from_filename() @test { - const String FNAME = "tmp/map_test_ro"; + String fname = random_name(); char[] msg = "Hello, world"; - write_file(FNAME, msg); + file::save(fname, msg)!!; - mmap::FileMmap mapped_file = file::mmap_open(FNAME, "rb", 0, 0, vm::VirtualMemoryAccess.READ)!!; + mmap::FileMmap mapped_file = file::mmap_open(fname, "rb", 0, 0, vm::VirtualMemoryAccess.READ)!!; defer mapped_file.destroy()!!; char[] view = mapped_file.bytes(); diff --git a/test/unit/stdlib/io/file_read_write_any.c3 b/test/unit/stdlib/io/file_read_write_any.c3 index 23e9eab45..fd01909aa 100644 --- a/test/unit/stdlib/io/file_read_write_any.c3 +++ b/test/unit/stdlib/io/file_read_write_any.c3 @@ -1,6 +1,5 @@ module std::io::file @test; - -import std::io; +import std::io, libc; struct Data { @@ -38,6 +37,7 @@ struct Data } } + fn void read_write_any() { Data data; @@ -57,13 +57,15 @@ fn void read_write_any() data.total = 0xA55A; data.hello = 0xCC; - File file = file::open("tmp/__file_read_write_any_test_file", "wb")!!; + char[1024] buf; + String name = libc::tmpnam(&buf).str_view(); + File file = file::open(name, "wb")!!; io::write_any(&file, &data)!!; file.flush()!!; file.close()!!; - file = file::open("tmp/__file_read_write_any_test_file", "rb")!!; + file = file::open(name, "rb")!!; Data rdata; io::read_any(&file, &rdata)!!;