commit cd68fa6697115b04b302dde790754585b31d299a
parent 0c736356bf7f1523b3a8a4081158b1e5755f5fb0
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 25 Feb 2021 19:28:15 -0500
rt+test: select tests from command line
Diffstat:
3 files changed, 38 insertions(+), 0 deletions(-)
diff --git a/rt/+test/cstring.ha b/rt/+test/cstring.ha
@@ -0,0 +1,16 @@
+fn c_strlen(cstr: *const char) size = {
+ const ptr = cstr: *[*]u8;
+ let ln = 0z;
+ for (ptr[ln] != 0; ln += 1) void;
+ return ln;
+};
+
+fn from_c_unsafe(cstr: *const char) const str = {
+ const l = c_strlen(cstr);
+ const s = struct {
+ data: *[*]u8 = cstr: *[*]u8,
+ length: size = l,
+ capacity: size = l,
+ };
+ return *(&s: *const str);
+};
diff --git a/rt/+test/start.ha b/rt/+test/start.ha
@@ -35,6 +35,9 @@ export @noreturn fn start_ha() void = {
print(" tests:\n\n");
time_start();
for (let i = 0z; i < ntest; i += 1) {
+ if (!should_test(test_start[i].name)) {
+ continue;
+ };
print(test_start[i].name);
dots(maxname - len(test_start[i].name) + 3);
print(" ");
@@ -97,3 +100,16 @@ fn dots(n: size) void = {
print(".");
};
};
+
+fn should_test(name: str) bool = {
+ if (argc == 1) {
+ return true;
+ };
+ for (let i = 1z; i < argc; i += 1) {
+ let s = from_c_unsafe(argv[i]);
+ if (name == s) {
+ return true;
+ };
+ };
+ return false;
+};
diff --git a/rt/ensure.ha b/rt/ensure.ha
@@ -4,8 +4,14 @@ export type slice = struct {
capacity: size,
};
+fn io::println(msgs: str...) void;
+fn strconv::ztos(z: size) str;
+
export fn ensure(s: *slice, membsz: size) void = {
let cap = s.capacity;
+ if (cap > s.length) {
+ return;
+ };
for (cap < s.length) {
assert(cap >= s.capacity, "slice out of memory (overflow)");
if (cap == 0) {