about summary refs log tree commit diff
path: root/nix/buildLisp/tests/argv0.nix
blob: ca5f2b9741e6d31d097a1dde319cf8104f4b749d (plain) (blame)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
{ depot, pkgs, lib, ... }:

let
  # Trivial test program that outputs argv[0] and exits
  prog =
    depot.nix.buildLisp.program {
      name = "argv0-test";

      srcs = [
        (pkgs.writeText "argv0-test.lisp" ''
          (defpackage :argv0-test (:use :common-lisp :uiop) (:export :main))
          (in-package :argv0-test)

          (defun main ()
            (format t "~A~%" (uiop:argv0)))
        '')
      ];

      deps = [
        {
          sbcl = depot.nix.buildLisp.bundled "uiop";
          default = depot.nix.buildLisp.bundled "asdf";
        }
      ];
    };

  # Extract verify argv[0] output for given buildLisp program
  checkImplementation = prog:
    pkgs.runCommand "check-argv0" { } ''
      set -eux

      checkInvocation() {
        invocation="$1"
        test "$invocation" = "$("$invocation")"
      }

      checkInvocation "${prog}/bin/argv0-test"

      cd ${prog}
      checkInvocation "./bin/argv0-test"

      cd bin
      checkInvocation ./argv0-test

      set +x

      touch "$out"
    '';

  inherit (prog.meta.ci) targets;
in

(checkImplementation prog).overrideAttrs (_: {
  # Wire up a subtarget all (active) non-default implementations
  passthru = lib.genAttrs targets (name: checkImplementation prog.${name});

  meta.ci = { inherit targets; };
})