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
;;; Copyright (c) 2026 Nicholas Vermeulen
;;; SPDX-License-Identifier: AGPL-3.0-or-later
;; pkg-test.lisp — golden test for pkg.lisp. No network: the fixture
;; packages are local git repositories under /tmp, installed via file://
;; URLs. Deterministic (fixed paths, no timestamps/hashes in output).
(load "pkg.lisp")
;; ── Build two fixture packages: rusty-pkg-fix depends on rusty-pkg-dep ──
(define (make-fixture dir manifest libfile libsrc)
(shell (format "rm -rf ~a" dir))
(dir-create dir)
(file-write (string-append dir "/package.lisp") manifest)
(file-write (string-append dir "/" libfile) libsrc)
(shell (format "cd ~a && git init -q && git add -A && git -c user.email=t@t -c user.name=t commit -qm fixture" dir)))
(make-fixture "/tmp/rusty-pkg-dep"
"((name \"rusty-pkg-dep\") (version \"0.1.0\") (main \"dep.lisp\"))"
"dep.lisp"
"(define (dep-triple x) (* 3 x))")
(make-fixture "/tmp/rusty-pkg-fix"
"((name \"rusty-pkg-fix\") (version \"1.2.0\") (main \"fix.lisp\") (deps (\"file:///tmp/rusty-pkg-dep\")))"
"fix.lisp"
"(define (fix-answer x) (+ (dep-triple x) 1))")
;; start clean (idempotent re-runs)
(pkg-remove "rusty-pkg-fix")
(pkg-remove "rusty-pkg-dep")
;; ── Install: pulls the dependency transitively ───────────────────────────
(print (pkg-install "file:///tmp/rusty-pkg-fix"))
(print (list 'dep-arrived-too (pkg-installed? "rusty-pkg-dep")))
(print (pkg-install "file:///tmp/rusty-pkg-fix")) ; second time: no-op
;; ── Load and actually use it (dep loads first) ───────────────────────────
(print (pkg-load "rusty-pkg-dep"))
(print (pkg-load "rusty-pkg-fix"))
(print (list 'fix-answer-of-5 (fix-answer 5))) ; 3*5+1 = 16
;; require-package on something already present: just loads
(print (require-package "file:///tmp/rusty-pkg-dep"))
;; ── Errors are informative, not crashes ──────────────────────────────────
(print (try-catch (pkg-load "no-such-package") (e) (list 'rejected e)))
(shell "rm -rf /tmp/rusty-not-a-pkg && mkdir -p /tmp/rusty-not-a-pkg && cd /tmp/rusty-not-a-pkg && git init -q && git -c user.email=t@t -c user.name=t commit -qm empty --allow-empty")
(print (try-catch (pkg-install "file:///tmp/rusty-not-a-pkg") (e) (list 'rejected e)))
;; ── Uninstall, leave the machine clean ───────────────────────────────────
(print (pkg-remove "rusty-pkg-fix"))
(print (pkg-remove "rusty-pkg-dep"))
(print (pkg-remove "rusty-pkg-fix")) ; already gone
(shell "rm -rf /tmp/rusty-pkg-fix /tmp/rusty-pkg-dep /tmp/rusty-not-a-pkg")
(print "PKG TESTS DONE")