commit 61dc4ff8dfb1d70eed51ad609064cdad70f53024
parent b69b8447865c176137271554c06656fa298615df
Author: Lou Woell <lou.woell@posteo.de>
Date:   Wed, 10 Sep 2025 23:49:57 +0200

tests for locate and list_symbols

Diffstat:
Acmd/harehelper/+test/list_test.ha | 21+++++++++++++++++++++
Acmd/harehelper/+test/locate_test.ha | 47+++++++++++++++++++++++++++++++++++++++++++++++
Mcmd/harehelper/+test/resolve_test.ha | 30+++++++++++++++---------------
Mcmd/harehelper/list_modules.ha | 2+-
4 files changed, 84 insertions(+), 16 deletions(-)

diff --git a/cmd/harehelper/+test/list_test.ha b/cmd/harehelper/+test/list_test.ha @@ -0,0 +1,21 @@ +use dirs; +use fmt; +use hare::module; +use hare::parse; +use os; + +@test fn list_symbols () void = { + const ctx = module::context { + harepath = os::tryenv("HAREPATH", HAREPATH), + harecache = match (os::getenv("HARECACHE")) { + case let s: str => + yield s; + case void => + yield dirs::cache("hare"); + }, + tags = ["linux"], + }; + + let res = list_symbols(&ctx, parse::identstr("test")!); + assert(len(res) == 3); +}; diff --git a/cmd/harehelper/+test/locate_test.ha b/cmd/harehelper/+test/locate_test.ha @@ -0,0 +1,47 @@ +use dirs; +use hare::lex; +use hare::module; +use hare::parse; +use os; +use strings; + +fn loc_test_fn (in: str, out: lex::location) void = { + const ctx = module::context { + harepath = os::tryenv("HAREPATH", HAREPATH), + harecache = match (os::getenv("HARECACHE")) { + case let s: str => + yield s; + case void => + yield dirs::cache("hare"); + }, + tags = ["linux"], + }; + + const id = parse::identstr(in)!; + + match(locate_symbol(&ctx, id)) { + case void => abort(); + case let l: lex::location => + assert(strings::hassuffix(l.path, out.path)); + assert(l.line == out.line); + assert(l.col == out.col); + }; +}; + +@test fn locate_stdlib() void = { + loc_test_fn("os::stdout", lex::location { + path = "stdfd.ha", + line = 29, + col = 7, + ... + }); +}; + +// @test fn locate_local() void = { +// loc_test_fn("cmd::harehelper::main", lex::location { +// path = "helper.ha", +// line = 45, +// col = 3, +// ... +// }); +// }; diff --git a/cmd/harehelper/+test/resolve_test.ha b/cmd/harehelper/+test/resolve_test.ha @@ -1,12 +1,12 @@ +use dirs; +use hare::ast; use hare::module::*; use hare::parse; -use hare::ast; -use os; -use memio::{concat, dynamic}; -use dirs; use m = math; +use memio::{concat, dynamic}; +use os; -fn test_fn (in: str, out: str) void = { +fn resolve_test_fn (in: str, out: str) void = { const ctx = context { harepath = os::tryenv("HAREPATH", HAREPATH), harecache = match (os::getenv("HARECACHE")) { @@ -26,42 +26,42 @@ fn test_fn (in: str, out: str) void = { match(res) { case void => abort(); case let i: ast::ident => - if(!ast::ident_eq(i, exp)) abort(); + assert(ast::ident_eq(i, exp)); }; }; @test fn resolve_wildcard_intern () void = { - test_fn("context", "hare::module::context"); + resolve_test_fn("context", "hare::module::context"); }; @test fn resolve_wildcard_module () void = { - test_fn("hare::module", "hare::module"); + resolve_test_fn("hare::module", "hare::module"); }; @test fn resolve_member_intern () void = { - test_fn("dynamic", "memio::dynamic"); + resolve_test_fn("dynamic", "memio::dynamic"); }; @test fn resolve_member_module () void = { - test_fn("memio", "memio"); + resolve_test_fn("memio", "memio"); }; @test fn resolve_module_noimport () void = { - test_fn("bufio", "bufio"); + resolve_test_fn("bufio", "bufio"); }; @test fn resolve_symbol_noimport () void = { - test_fn("bufio::finish", "bufio::finish"); + resolve_test_fn("bufio::finish", "bufio::finish"); }; @test fn resolve_symbol_import () void = { - test_fn("parse::identstr", "hare::parse::identstr"); + resolve_test_fn("parse::identstr", "hare::parse::identstr"); }; @test fn resolve_alias_symbol () void = { - test_fn("m::absi", "math::absi"); + resolve_test_fn("m::absi", "math::absi"); }; @test fn resolve_alias_module () void = { - test_fn("m", "math"); + resolve_test_fn("m", "math"); }; diff --git a/cmd/harehelper/list_modules.ha b/cmd/harehelper/list_modules.ha @@ -33,7 +33,7 @@ fn get_modules (ctx: *module::context) []module::module = { match (r) { case let e: hare::module::error => - fmt::println(module::strerror(e))!; + fmt::errorln(module::strerror(e))!; case => void; }; };