summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/ha/hare/mime-module-test.nix
blob: ef53bee8c3bc3e0bcb01aee4715c2183b2150c44 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
  hare,
  runCommand,
  writeText,
}:
let
  mainDotHare = writeText "main.ha" ''
    use fmt;
    use mime;
    export fn main() void = {
        const ext = "json";
        match(mime::lookup_ext(ext)) {
        case let mime: const *mime::mimetype =>
          fmt::printfln("Found mimetype for extension `{}`: {}", ext, mime.mime)!;
        case null =>
          fmt::fatalf("Could not find mimetype for `{}`", ext);
        };
      };
  '';
in
runCommand "mime-module-test" { nativeBuildInputs = [ hare ]; } ''
  HARECACHE="$(mktemp -d)"
  export HARECACHE
  readonly binout="test-bin"
  hare build -qRo "$binout" ${mainDotHare}
  ./$binout
  : 1>$out
''