commit c4d2b2c8b1cf853b5f0e324073e9cf24ca0aeeaa
parent 995b64277541d29df3162b4521c2eae196ad8eb1
Author: Drew DeVault <sir@cmpwn.com>
Date: Thu, 4 Feb 2021 14:43:38 -0500
rt +test: add more logging
Diffstat:
2 files changed, 50 insertions(+), 0 deletions(-)
diff --git a/rt/+test/start.ha b/rt/+test/start.ha
@@ -35,13 +35,25 @@ export fn start_ha() void = {
};
};
+ let npass = 0z, nfail = 0z;
+ print("Running ");
+ print(ztos(ntest));
+ print(" tests:\n\n");
for (let i = 0z; i < ntest; i += 1z) {
print(test_start[i].name);
dots(maxname - len(test_start[i].name) + 3z);
print(" ");
test_start[i].func();
+ npass += 1z;
print("OK\n");
};
+ print("\n");
+ print(ztos(npass));
+ print(" passed; ");
+ print(ztos(nfail));
+ print(" failed; ");
+ print(ztos(ntest));
+ print(" tests completed.\n");
const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
/ size(*fn() void);
diff --git a/rt/+test/ztos.ha b/rt/+test/ztos.ha
@@ -0,0 +1,38 @@
+fn bytes_reverse(b: []u8) void = {
+ if (len(b) == 0z) {
+ return;
+ };
+ for (let s = 0z, e = len(b) - 1z; s < e) {
+ let x = b[s];
+ b[s] = b[e];
+ b[e] = x;
+ s += 1z;
+ e -= 1z;
+ };
+};
+
+fn ztos(u: size) const str = {
+ static let buf: [21]u8 = [0u8...]; // 20 digits plus NUL
+ buf = [0u8...];
+
+ let s = struct {
+ b: *[*]u8 = &buf,
+ l: size = 0z,
+ c: size = 0z,
+ };
+
+ if (u == 0z) {
+ s.b[s.l] = '0': u32: u8;
+ s.l += 1z;
+ };
+
+ for (u > 0z) {
+ s.b[s.l] = '0': u32: u8 + (u % 10z): u8;
+ s.l += 1z;
+ u /= 10z;
+ };
+
+ bytes_reverse(s.b[..s.l]);
+ s.b[s.l] = 0u8;
+ return *(&s: *str);
+};