commit: a8077898b967386c3973a1e077cc06911b8921ae
parent a66135963e4fc1ee9fabf26f82ec5af4736e624d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 18 Feb 2022 01:17:46 +0100
Add tests for is_blob
Diffstat:
5 files changed, 46 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -1 +1,4 @@
-/deblob
-\ No newline at end of file
+/deblob
+/test/fixtures/hello
+/test/fixtures/hello.a
+/test/fixtures/hello.o
diff --git a/main.ha b/main.ha
@@ -44,6 +44,30 @@ fn is_blob(filename: str) (bool|invalid) = {
return bytes::hasprefix(buffer, elf) || bytes::hasprefix(buffer, ar) || bytes::hasprefix(buffer, bios);
};
+@test fn is_blob() void = {
+ let tests = [
+ ("test/fixtures/hello.1", false),
+ ("test/fixtures/hello.c", false),
+ ("test/fixtures/hello", true),
+ ("test/fixtures/hello.o", true),
+ ("test/fixtures/hello.a", true),
+ //("test/fixtures/option.rom", true),
+ ];
+
+ for(let i = 0z; i < len(tests); i += 1) {
+ match(is_blob(tests[i].0)) {
+ case let got: bool =>
+ if(got != tests[i].1) {
+ fmt::fatal("is_blob({}) was incorrect, got {}, expected {}", tests[i].0, got, tests[i].1);
+ };
+ case invalid =>
+ fmt::fatal("is_blob({}) was incorrect, got invalid, expected {}", tests[i].0, tests[i].1);
+ };
+ };
+
+ assert(is_blob("test/fixtures/empty") is invalid);
+};
+
fn is_excluded(filename: str) bool = {
for (let i = 0z; i < len(excludes); i += 1) {
if (fnmatch::fnmatch(excludes[i], filename, fnmatch::flags::NONE)) {
diff --git a/test/fixtures/empty b/test/fixtures/empty
diff --git a/test/fixtures/hello.1 b/test/fixtures/hello.1
@@ -0,0 +1,12 @@
+.Dd 2019-12-12
+.Dt hello 1
+.Os
+.Sh NAME
+.Nm hello
+.Nd greets
+.Sh SYNOPSIS
+.Nm
+.Sh DESCRIPTION
+Greats the user with a message.
+.Sh EXIT STATUS
+.Ex -std
diff --git a/test/fixtures/hello.c b/test/fixtures/hello.c
@@ -0,0 +1,5 @@
+#include <stdio.h> /* printf() */
+
+int main(void) {
+ return printf("Hello World!\n");
+}
+\ No newline at end of file