commit 6011389265860e02cdf71870ae5e5ba7aaca8e9c
parent 4fedf29d249ec7366f18f1ffda3b52293624fd2c
Author: Eyal Sawady <ecs@d2evs.net>
Date: Sat, 24 Apr 2021 10:04:26 -0400
Fix error handling oversights in tests
Signed-off-by: Eyal Sawady <ecs@d2evs.net>
Diffstat:
13 files changed, 44 insertions(+), 41 deletions(-)
diff --git a/bufio/memstream.ha b/bufio/memstream.ha
@@ -246,7 +246,7 @@ fn seek(
n += io::write(stream, strings::toutf8("world")) as size;
assert(bytes::equal(buf[..n], strings::toutf8("hello world")));
// TODO: this should check for errors::unsupported (harec bug prevents that)
- io::seek(stream, 6, io::whence::SET) as io::error;
+ io::seek(stream, 6, io::whence::SET) as io::error: void;
let out: [2]u8 = [0...];
let s = fixed([1u8, 2u8], io::mode::READ);
diff --git a/compress/flate/inflate.ha b/compress/flate/inflate.ha
@@ -415,7 +415,7 @@ fn close(s: *io::stream) void = {
match (io::copy(outs, s)) {
_: size => void,
e: io::error => {
- fmt::errorln(io::strerror(e));
+ fmt::errorln(io::strerror(e))!;
abort();
},
};
diff --git a/compress/zlib/reader.ha b/compress/zlib/reader.ha
@@ -122,14 +122,14 @@ export fn decompress(s: *io::stream) (*io::stream | io::error) = {
let d = match (decompress(in)) {
s: *io::stream => s,
e: io::error => {
- fmt::errorln(io::strerror(e));
+ fmt::errorln(io::strerror(e))!;
abort();
},
};
match (io::copy(out, d)) {
_: size => void,
e: io::error => {
- fmt::errorfln("vector {}: {}", i, io::strerror(e));
+ fmt::errorfln("vector {}: {}", i, io::strerror(e))!;
abort();
},
};
diff --git a/crypto/md5/+test.ha b/crypto/md5/+test.ha
@@ -34,7 +34,7 @@ use io;
};
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
diff --git a/crypto/sha1/+test.ha b/crypto/sha1/+test.ha
@@ -38,7 +38,7 @@ use io;
};
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
diff --git a/crypto/sha256/+test.ha b/crypto/sha256/+test.ha
@@ -36,7 +36,7 @@ use strio;
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
diff --git a/crypto/sha512/+test.ha b/crypto/sha512/+test.ha
@@ -32,12 +32,13 @@ use io;
let hex = strio::dynamic();
defer io::close(hex);
- for (let j = 0z; j < len(sum); j += 1)
- fmt::fprintf(hex, "{:02x}", sum[j]);
+ for (let j = 0z; j < len(sum); j += 1) {
+ fmt::fprintf(hex, "{:02x}", sum[j])!;
+ };
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
@@ -69,7 +70,7 @@ use io;
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
@@ -95,12 +96,13 @@ use io;
let hex = strio::dynamic();
defer io::close(hex);
- for (let j = 0z; j < len(sum); j += 1)
- fmt::fprintf(hex, "{:02x}", sum[j]);
+ for (let j = 0z; j < len(sum); j += 1) {
+ fmt::fprintf(hex, "{:02x}", sum[j])!;
+ };
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
@@ -127,12 +129,13 @@ use io;
let hex = strio::dynamic();
defer io::close(hex);
- for (let j = 0z; j < len(sum); j += 1)
- fmt::fprintf(hex, "{:02x}", sum[j]);
+ for (let j = 0z; j < len(sum); j += 1) {
+ fmt::fprintf(hex, "{:02x}", sum[j])!;
+ };
if (strio::string(hex) != vector.1) {
fmt::errorfln("Vector {}: {} != {}",
- i, strio::string(hex), vector.1);
+ i, strio::string(hex), vector.1)!;
abort();
};
};
diff --git a/encoding/hex/hex.ha b/encoding/hex/hex.ha
@@ -62,7 +62,7 @@ export fn decode(s: str) ([]u8 | invalid) = {
defer free(s);
assert(bytes::equal(s, [0xCA, 0xFE, 0xBA, 0xBE, 0xDE, 0xAD, 0xF0, 0x0D]));
- decode("this is not hex") as invalid;
+ decode("this is not hex") as invalid: void;
};
// Outputs a dump of hex data to a stream alongside the offset and an ASCII
diff --git a/format/html/escape.ha b/format/html/escape.ha
@@ -25,16 +25,16 @@ export fn escape(out: *io::stream, in: str) (size | io::error) = {
@test fn escape() void = {
let sink = strio::dynamic();
defer io::close(sink);
- escape(sink, "hello world!");
+ escape(sink, "hello world!")!;
assert(strio::string(sink) == "hello world!");
let sink = strio::dynamic();
defer io::close(sink);
- escape(sink, "\"hello world!\"");
+ escape(sink, "\"hello world!\"")!;
assert(strio::string(sink) == ""hello world!"");
let sink = strio::dynamic();
defer io::close(sink);
- escape(sink, "<hello & 'world'!>");
+ escape(sink, "<hello & 'world'!>")!;
assert(strio::string(sink) == "<hello & 'world'!>");
};
diff --git a/fs/mem/+test.ha b/fs/mem/+test.ha
@@ -17,7 +17,7 @@ use strconv;
for (let i = 0z; i < 6; i += 1) {
let f = fs::create(memfs, names[i], 0, fs::flags::RDWR);
let f = f as *io::stream;
- io::write(f, input[i..]);
+ io::write(f, input[i..])!;
io::close(f);
let st = fs::stat(memfs, names[i]) as fs::filestat;
assert(st.mask & fs::stat_mask::SIZE == fs::stat_mask::SIZE);
@@ -27,18 +27,18 @@ use strconv;
let f = fs::open(memfs, filename, fs::flags::WRONLY, fs::flags::APPEND);
let f = f as *io::stream;
- io::write(f, input);
+ io::write(f, input)!;
io::close(f);
let st = fs::stat(memfs, filename) as fs::filestat;
assert(st.sz == len(input) * 2);
- fs::create(memfs, filename, 0, fs::flags::RDONLY) as fs::error; // errors::exists
+ fs::create(memfs, filename, 0, fs::flags::RDONLY) as fs::error: void; // errors::exists
// fs::open and read
- fs::open(memfs, "nonexistent", fs::flags::RDONLY) as fs::error; // errors::noentry
+ fs::open(memfs, "nonexistent", fs::flags::RDONLY) as fs::error: void; // errors::noentry
let f = fs::open(memfs, filename, fs::flags::RDWR, fs::flags::EXCL);
- f as fs::error; // errors::unsupported
- fs::remove(memfs, "nonexistent") as fs::error; // errors::noentry
+ f as fs::error: void; // errors::unsupported
+ fs::remove(memfs, "nonexistent") as fs::error: void; // errors::noentry
let f = fs::open(memfs, filename, fs::flags::RDONLY) as *io::stream;
let f2 = fs::open(memfs, filename, fs::flags::RDONLY) as *io::stream;
@@ -62,15 +62,15 @@ use strconv;
assert(count == 6);
// fs::mkdir
- fs::mkdir(memfs, "nonexistent/path") as fs::error; // errors::noentry
- fs::rmdir(memfs, "nonexistent/path") as fs::error; // errors::noentry
+ fs::mkdir(memfs, "nonexistent/path") as fs::error: void; // errors::noentry
+ fs::rmdir(memfs, "nonexistent/path") as fs::error: void; // errors::noentry
fs::mkdir(memfs, "dir") as void;
- fs::open(memfs, "dir", fs::flags::RDONLY) as fs::error; // fs::wrongtype
- fs::mkdir(memfs, "dir") as fs::error; // errors::exists
+ fs::open(memfs, "dir", fs::flags::RDONLY) as fs::error: void; // fs::wrongtype
+ fs::mkdir(memfs, "dir") as fs::error: void; // errors::exists
fs::mkdir(memfs, "dir/subdir") as void;
fs::rmdir(memfs, "dir/subdir") as void;
fs::rmdir(memfs, "dir") as void;
- fs::rmdir(memfs, "") as fs::error; // errors::invalid;
+ fs::rmdir(memfs, "") as fs::error: void; // errors::invalid;
fs::mkdir(memfs, "dir") as void;
f = fs::create(memfs, "dir/file", 0, fs::flags::WRONLY) as *io::stream;
@@ -85,13 +85,13 @@ use strconv;
fs::rmdir(memfs, "dir") as void;
// fs::mksubdir, fs::subdir
- fs::mksubdir(memfs, filename) as fs::error; // errors::exists
- fs::subdir(memfs, filename) as fs::error; // fs::wrongtype
+ fs::mksubdir(memfs, filename) as fs::error: void; // errors::exists
+ fs::subdir(memfs, filename) as fs::error: void; // fs::wrongtype
let sub = mksubdir(memfs, "dir") as *fs::fs;
let f = fs::create(sub, "file", 0, fs::flags::WRONLY) as *io::stream;
- io::write(f, [42]);
+ io::write(f, [42])!;
io::close(f);
let sub2 = fs::subdir(memfs, "dir") as *fs::fs;
@@ -112,7 +112,7 @@ use strconv;
fs::rmdir(sub2, "subdir") as void;
assert(memsub2.opencount == 1);
assert(memsub2.parent == null);
- fs::rmdirall(sub2, "");
+ fs::rmdirall(sub2, "")!;
fs::close(sub2);
};
diff --git a/hare/lex/+test.ha b/hare/lex/+test.ha
@@ -50,7 +50,7 @@ fn lextest(in: str, expected: []token) void = {
let tl = match (lex(&lexer)) {
tl: token => tl,
err: error => {
- fmt::errorfln("{}: {}", i, strerror(err));
+ fmt::errorfln("{}: {}", i, strerror(err))!;
abort();
},
};
diff --git a/hare/parse/+test/roundtrip.ha b/hare/parse/+test/roundtrip.ha
@@ -17,7 +17,7 @@ fn roundtrip(src: str) void = {
decls: []ast::decl = match (decls(&lexer)) {
decls: []ast::decl => decls,
err: error => {
- fmt::errorln(strerror(err));
+ fmt::errorln(strerror(err))!;
abort();
},
},
@@ -28,8 +28,8 @@ fn roundtrip(src: str) void = {
let unsrc = strio::finish(out);
defer free(unsrc);
if (unsrc != src) {
- fmt::errorfln("=== wanted\n{}", src);
- fmt::errorfln("=== got\n{}", unsrc);
+ fmt::errorfln("=== wanted\n{}", src)!;
+ fmt::errorfln("=== got\n{}", unsrc)!;
abort();
};
};
diff --git a/hare/parse/+test/unit.ha b/hare/parse/+test/unit.ha
@@ -143,7 +143,7 @@ use strings;
let decls = match (decls(&lexer)) {
decls: []ast::decl => decls,
err: error => {
- fmt::errorln(strerror(err));
+ fmt::errorln(strerror(err))!;
abort();
},
};