commit daf3007d61c7b40e3873fea76febf3b59f09ff80
parent 1f4be2a229924cca4e9cd38a146cf2d725557f20
Author: Lou Woell <lou.woell@posteo.de>
Date: Mon, 6 Oct 2025 22:14:55 +0200
[find_refs] add tests
Diffstat:
1 file changed, 72 insertions(+), 0 deletions(-)
diff --git a/cmd/harehelper/+test/find_references.ha b/cmd/harehelper/+test/find_references.ha
@@ -0,0 +1,72 @@
+use os;
+use hare::module;
+use path;
+use dirs;
+use fmt;
+
+@test fn scan_tree_local_test () void = {
+
+ const ctx = module::context {
+ harepath = harepath(),
+ harecache = match (os::getenv("harecache")) {
+ case let s: str =>
+ yield s;
+ case void =>
+ yield dirs::cache("hare");
+ },
+ tags = ["linux", "test"],
+ };
+
+ let p = path::init(".")!;
+ let r = scan_tree(&ctx, &p, ["scan_tree"]);
+
+ fmt::errorfln("found \"scan_tree\" in {} files", len(r))!;
+ assert(len(r) == 2);
+};
+
+@test fn scan_file_local () void = {
+
+ let p = path::init(".")!;
+ let r = scan_file("./cmd/harehelper/find_refs.ha", ["scan_tree"]);
+
+ assert(len(r as []xref) == 2);
+};
+
+@test fn scan_tree_stdlib () void = {
+
+ const ctx = module::context {
+ harepath = harepath(),
+ harecache = match (os::getenv("harecache")) {
+ case let s: str =>
+ yield s;
+ case void =>
+ yield dirs::cache("hare");
+ },
+ tags = ["linux", "test"],
+ };
+
+ let p = path::init(".")!;
+ let r = scan_tree(&ctx, &p, ["fmt", "println"]);
+
+ assert(len(r) != 0);
+};
+
+@test fn scan_tree_local_ns () void = {
+
+ const ctx = module::context {
+ harepath = harepath(),
+ harecache = match (os::getenv("harecache")) {
+ case let s: str =>
+ yield s;
+ case void =>
+ yield dirs::cache("hare");
+ },
+ tags = ["linux", "test"],
+ };
+
+ let p = path::init(".")!;
+ let r = scan_tree(&ctx, &p, ["cmd", "harehelper", "scan_tree"]);
+
+ fmt::errorfln("found \"cmd::harehelper::scan_tree\" in {} files", len(r))!;
+ assert(len(r) == 2);
+};