- Test runner will also check for leaks.

- `write` of qoi would leak memory.
- Issue when having an empty `Path` or just "."
- `set_env` would leak memory.
This commit is contained in:
Christoffer Lerno
2025-02-10 00:39:02 +01:00
parent 63f619e5b6
commit c4212c4649
20 changed files with 81 additions and 41 deletions

View File

@@ -5,7 +5,7 @@ fn void write_read()
{
ByteBuffer buffer;
buffer.new_init(0)!!;
defer buffer.free();
buffer.write("hello")!!;
char[8] bytes;

View File

@@ -13,6 +13,7 @@ fn void bytestream()
assert((String)buffer[:len] == "abc");
ByteWriter w;
w.new_init();
defer (void)w.destroy();
OutStream ws = &w;
ws.write("helloworld")!!;
assert(w.str_view() == "helloworld");

View File

@@ -4,10 +4,12 @@ fn void test_writing()
{
DString foo;
foo.new_init();
defer foo.free();
OutStream s = &foo;
s.write("hello")!!;
s.write_byte('-')!!;
s.write("what?-------------------------------------------------------")!!;
ByteReader r;
String test_str = "2134";
io::copy_to(r.init(test_str), s)!!;

View File

@@ -3,9 +3,11 @@ module std::io::path @test;
fn void test_dot()
{
Path p = path::new(".")!!;
defer p.free();
assert(@catch(p.parent()));
// It must be possible to form the absolute version.
Path p2 = p.new_absolute()!!;
p2.free();
p2 = p.new_append("/hello/world")!!;
if (p2.env == POSIX)
{
@@ -15,21 +17,26 @@ fn void test_dot()
{
assert(p2.str_view() == `hello\world`);
}
p2.free();
}
fn void test_parent()
{
Path p = path::new("")!!;
assert(@catch(p.parent()));
p.free();
p = path::new("/", path_env: PathEnv.POSIX)!!;
assert(@catch(p.parent()));
p.free();
p = path::new("/a/b/c", path_env: PathEnv.POSIX)!!;
assert(p.parent().str_view()!! == "/a/b");
p.free();
p = path::new("/a/b/c", path_env: PathEnv.WIN32)!!;
assert(p.parent().str_view()!! == `\a\b`);
p.free();
}
fn void test_path_normalized()
fn void test_path_normalized() => mem::@scoped(allocator::temp())
{
assert(path::new("", path_env: PathEnv.WIN32).str_view()!! == "");
assert(@catch(path::new("1:\\a\\b\\c.txt", path_env: PathEnv.WIN32)));
@@ -205,7 +212,7 @@ fn void test_path_normalized()
}
fn void test_extension()
fn void test_extension() => mem::@scoped(allocator::temp())
{
assert(@catch(path::new(`C:`, path_env: PathEnv.WIN32).extension()));
assert(@catch(path::new(`C:`, path_env: PathEnv.POSIX).extension()));
@@ -239,7 +246,7 @@ fn void test_extension()
}
fn void test_has_extension()
fn void test_has_extension() => mem::@scoped(allocator::temp())
{
assert(!path::new(`C:\temp\foo.bar\README`, path_env: PathEnv.WIN32)!!.has_extension(`bar\README`));
@@ -269,7 +276,7 @@ fn void test_has_extension()
}
fn void test_basename()
fn void test_basename() => mem::@scoped(allocator::temp())
{
assert(path::new_windows("file.txt").basename()!! == "file.txt");
assert(path::new_posix("file.txt").basename()!! == "file.txt");
@@ -296,7 +303,7 @@ fn void test_basename()
assert(path::new_posix(`\\server\abc`).basename()!! == `\\server\abc`);
}
fn void test_dirname()
fn void test_dirname() => mem::@scoped(allocator::temp())
{
assert(path::new_posix("").dirname()!! == ".");
assert(path::new_posix("/file").dirname()!! == "/");
@@ -336,7 +343,7 @@ fn void test_dirname()
assert(path::new_posix(`\\server\`).dirname()!! == `.`);
}
fn void test_path_volume()
fn void test_path_volume() => mem::@scoped(allocator::temp())
{
assert(path::new_windows(`C:\abs`).volume_name()!! == `C:`);
assert(path::new_windows(`C:abs`).volume_name()!! == `C:`);
@@ -346,7 +353,7 @@ fn void test_path_volume()
assert(path::new_windows(`\\server\foo\abc`).volume_name()!! == `\\server\foo`);
}
fn void test_path_is_absolute()
fn void test_path_is_absolute() => mem::@scoped(allocator::temp())
{
assert(!path::new_posix("").is_absolute()!!);
assert(path::new_posix("/").is_absolute()!!);
@@ -360,7 +367,7 @@ fn void test_path_is_absolute()
assert(path::new_windows(`\\server\foo\abc`).is_absolute()!!);
}
fn void test_path_absolute()
fn void test_path_absolute() => mem::@scoped(allocator::temp())
{
$if env::WIN32:
assert(path::new_windows(`C:\abs`).new_absolute()!!.str_view() == `C:\abs`);

View File

@@ -27,6 +27,7 @@ fn void scanner()
sc.init(&br, buffer[..]);
Results results;
defer results.free();
while LOOP: (true)
{
char[]! res = sc.scan(",,");

View File

@@ -77,6 +77,7 @@ fn void read_tiny_bytearray_test()
ByteReader reader = io::wrap_bytes(&&x'07aabbcc00112233');
char[] read = io::read_tiny_bytearray(&reader, allocator: allocator::heap())!!;
assert(read == &&x'aabbcc00112233');
free(read);
}
fn void read_short_bytearray_test()
@@ -84,4 +85,5 @@ fn void read_short_bytearray_test()
ByteReader reader = io::wrap_bytes(&&x'0007aabbcc00112233');
char[] read = io::read_short_bytearray(&reader, allocator: allocator::heap())!!;
assert(read == &&x'aabbcc00112233');
free(read);
}