summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSarah Morgensen <iskarian@mgsn.dev>2021-07-16 21:01:28 -0700
committerMaxim Cournoyer <maxim.cournoyer@gmail.com>2021-07-18 01:57:17 -0400
commit793ba333c6039545684e8af7e384704e76bc0f2f (patch)
tree2705d7a6da51a129ff441820199a485b1cce852b /tests
parent3217a04b0352c2dd13323257b369604eeabfccc3 (diff)
import: go: Upgrade go.mod parser.
Upgrade the go.mod parser to handle the full go.mod spec, and to gracefully handle unexpected/malformed syntax. Restructure parser usage, making the parse tree available for other uses. guix/import/go.scm (parse-go.mod): Parse using (ice-9 peg) instead of regex matching for more robustness. Return a list of directives. (go.mod-directives): New procedure. (go.mod-requirements): Likewise. (go-module->guix-package): Use it. (%go.mod-replace-directive-rx): Remove unused variable. tests/go.scm (testing-parse-mod): Adjust accordingly. (go.mod-requirements) (fixture-go-mod-unparseable) (fixture-go-mod-retract) (fixture-go-mod-strings): New variables. ("parse-go.mod: simple") ("parse-go.mod: comments and unparseable lines") ("parse-go.mod: retract") ("parse-go.mod: raw strings and quoted strings") ("parse-go.mod: complete"): New tests. Signed-off-by: Maxim Cournoyer <maxim.cournoyer@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/go.scm133
1 files changed, 132 insertions, 1 deletions
diff --git a/tests/go.scm b/tests/go.scm
index 2dfdc97eb5c..6749f4585ff 100644
--- a/tests/go.scm
+++ b/tests/go.scm
@@ -1,5 +1,6 @@
1;;; GNU Guix --- Functional package management for GNU 1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com> 2;;; Copyright © 2021 François Joulaud <francois.joulaud@radiofrance.com>
3;;; Copyright © 2021 Sarah Morgensen <iskarian@mgsn.dev>
3;;; 4;;;
4;;; This file is part of GNU Guix. 5;;; This file is part of GNU Guix.
5;;; 6;;;
@@ -31,6 +32,9 @@
31 #:use-module (srfi srfi-64) 32 #:use-module (srfi srfi-64)
32 #:use-module (web response)) 33 #:use-module (web response))
33 34
35(define go.mod-requirements
36 (@@ (guix import go) go.mod-requirements))
37
34(define parse-go.mod 38(define parse-go.mod
35 (@@ (guix import go) parse-go.mod)) 39 (@@ (guix import go) parse-go.mod))
36 40
@@ -95,6 +99,41 @@ replace (
95 99
96") 100")
97 101
102(define fixture-go-mod-unparseable
103 "module my/thing
104go 1.12 // avoid feature X
105require other/thing v1.0.2
106// Security issue: CVE-XXXXX
107exclude old/thing v1.2.3
108new-directive another/thing yet-another/thing
109replace (
110 bad/thing v1.4.5 => good/thing v1.4.5
111 // Unparseable
112 bad/thing [v1.4.5, v1.9.7] => good/thing v2.0.0
113)
114")
115
116(define fixture-go-mod-retract
117 "retract v0.9.1
118
119retract (
120 v1.9.2
121 [v1.0.0, v1.7.9]
122)
123")
124
125(define fixture-go-mod-strings
126 "require `example.com/\"some-repo\"` v1.9.3
127require (
128 `example.com/\"another.repo\"` v1.0.0
129 \"example.com/special!repo\" v9.3.1
130)
131replace \"example.com/\\\"some-repo\\\"\" => `launchpad.net/some-repo` v1.9.3
132replace (
133 \"example.com/\\\"another.repo\\\"\" => launchpad.net/another-repo v1.0.0
134)
135")
136
98(define fixtures-go-check-test 137(define fixtures-go-check-test
99 (let ((version 138 (let ((version
100 "{\"Version\":\"v0.0.0-20201130134442-10cb98267c6c\",\"Time\":\"2020-11-30T13:44:42Z\"}") 139 "{\"Version\":\"v0.0.0-20201130134442-10cb98267c6c\",\"Time\":\"2020-11-30T13:44:42Z\"}")
@@ -178,7 +217,7 @@ require github.com/kr/pretty v0.2.1
178 (string<? (car p1) (car p2))) 217 (string<? (car p1) (car p2)))
179 (test-equal name 218 (test-equal name
180 (sort expected inf?) 219 (sort expected inf?)
181 (sort ((@@ (guix import go) parse-go.mod) input) inf?))) 220 (sort (go.mod-requirements (parse-go.mod input)) inf?)))
182 221
183(testing-parse-mod "parse-go.mod-simple" 222(testing-parse-mod "parse-go.mod-simple"
184 '(("good/thing" "v1.4.5") 223 '(("good/thing" "v1.4.5")
@@ -214,6 +253,98 @@ require github.com/kr/pretty v0.2.1
214 ("github.com/go-check/check" "v0.0.0-20140225173054-eb6ee6f84d0a")) 253 ("github.com/go-check/check" "v0.0.0-20140225173054-eb6ee6f84d0a"))
215 fixture-go-mod-complete) 254 fixture-go-mod-complete)
216 255
256(test-equal "parse-go.mod: simple"
257 `((module (module-path "my/thing"))
258 (go (version "1.12"))
259 (require (module-path "other/thing") (version "v1.0.2"))
260 (require (module-path "new/thing/v2") (version "v2.3.4"))
261 (exclude (module-path "old/thing") (version "v1.2.3"))
262 (replace (original (module-path "bad/thing") (version "v1.4.5"))
263 (with (module-path "good/thing") (version "v1.4.5"))))
264 (parse-go.mod fixture-go-mod-simple))
265
266(test-equal "parse-go.mod: comments and unparseable lines"
267 `((module (module-path "my/thing"))
268 (go (version "1.12") (comment "avoid feature X"))
269 (require (module-path "other/thing") (version "v1.0.2"))
270 (comment "Security issue: CVE-XXXXX")
271 (exclude (module-path "old/thing") (version "v1.2.3"))
272 (unknown "new-directive another/thing yet-another/thing")
273 (replace (original (module-path "bad/thing") (version "v1.4.5"))
274 (with (module-path "good/thing") (version "v1.4.5")))
275 (comment "Unparseable")
276 (unknown "bad/thing [v1.4.5, v1.9.7] => good/thing v2.0.0"))
277 (parse-go.mod fixture-go-mod-unparseable))
278
279(test-equal "parse-go.mod: retract"
280 `((retract (version "v0.9.1"))
281 (retract (version "v1.9.2"))
282 (retract (range (version "v1.0.0") (version "v1.7.9"))))
283 (parse-go.mod fixture-go-mod-retract))
284
285(test-equal "parse-go.mod: raw strings and quoted strings"
286 `((require (module-path "example.com/\"some-repo\"") (version "v1.9.3"))
287 (require (module-path "example.com/\"another.repo\"") (version "v1.0.0"))
288 (require (module-path "example.com/special!repo") (version "v9.3.1"))
289 (replace (original (module-path "example.com/\"some-repo\""))
290 (with (module-path "launchpad.net/some-repo") (version "v1.9.3")))
291 (replace (original (module-path "example.com/\"another.repo\""))
292 (with (module-path "launchpad.net/another-repo") (version "v1.0.0"))))
293 (parse-go.mod fixture-go-mod-strings))
294
295(test-equal "parse-go.mod: complete"
296 `((module (module-path "M"))
297 (go (version "1.13"))
298 (replace (original (module-path "github.com/myname/myproject/myapi"))
299 (with (file-path "./api")))
300 (replace (original (module-path "github.com/mymname/myproject/thissdk"))
301 (with (file-path "../sdk")))
302 (replace (original (module-path "launchpad.net/gocheck"))
303 (with (module-path "github.com/go-check/check")
304 (version "v0.0.0-20140225173054-eb6ee6f84d0a")))
305 (require (module-path "github.com/user/project")
306 (version "v1.1.11"))
307 (require (module-path "github.com/user/project/sub/directory")
308 (version "v1.1.12"))
309 (require (module-path "bitbucket.org/user/project")
310 (version "v1.11.20"))
311 (require (module-path "bitbucket.org/user/project/sub/directory")
312 (version "v1.11.21"))
313 (require (module-path "launchpad.net/project")
314 (version "v1.1.13"))
315 (require (module-path "launchpad.net/project/series")
316 (version "v1.1.14"))
317 (require (module-path "launchpad.net/project/series/sub/directory")
318 (version "v1.1.15"))
319 (require (module-path "launchpad.net/~user/project/branch")
320 (version "v1.1.16"))
321 (require (module-path "launchpad.net/~user/project/branch/sub/directory")
322 (version "v1.1.17"))
323 (require (module-path "hub.jazz.net/git/user/project")
324 (version "v1.1.18"))
325 (require (module-path "hub.jazz.net/git/user/project/sub/directory")
326 (version "v1.1.19"))
327 (require (module-path "k8s.io/kubernetes/subproject")
328 (version "v1.1.101"))
329 (require (module-path "one.example.com/abitrary/repo")
330 (version "v1.1.111"))
331 (require (module-path "two.example.com/abitrary/repo")
332 (version "v0.0.2"))
333 (require (module-path "quoted.example.com/abitrary/repo")
334 (version "v0.0.2"))
335 (replace (original (module-path "two.example.com/abitrary/repo"))
336 (with (module-path "github.com/corp/arbitrary-repo")
337 (version "v0.0.2")))
338 (replace (original (module-path "golang.org/x/sys"))
339 (with (module-path "golang.org/x/sys")
340 (version "v0.0.0-20190813064441-fde4db37ae7a"))
341 (comment "pinned to release-branch.go1.13"))
342 (replace (original (module-path "golang.org/x/tools"))
343 (with (module-path "golang.org/x/tools")
344 (version "v0.0.0-20190821162956-65e3620a7ae7"))
345 (comment "pinned to release-branch.go1.13")))
346 (parse-go.mod fixture-go-mod-complete))
347
217;;; End-to-end tests for (guix import go) 348;;; End-to-end tests for (guix import go)
218(define (mock-http-fetch testcase) 349(define (mock-http-fetch testcase)
219 (lambda (url . rest) 350 (lambda (url . rest)