mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
- Remove dependency on test tmp library for stdlib compiler tests. #2800
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
- Attrdef eval environment lacked rtype, causing error on invalid args #2797
|
||||
- $typeof(<type>) 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.
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)!!;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user