Skip to content

Commit 9e0054e

Browse files
committed
refactor(spec): move tests to the file, fix some tests
Signed-off-by: Kaiyang Wu <[email protected]>
1 parent 385fd1b commit 9e0054e

File tree

3 files changed

+177
-183
lines changed

3 files changed

+177
-183
lines changed

aosc-test/main.rkt

Lines changed: 0 additions & 12 deletions
This file was deleted.

aosc-test/spec-test.rkt

Lines changed: 0 additions & 170 deletions
This file was deleted.

aosc/private/spec.rkt

Lines changed: 177 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
spec
2525
write-spec)
2626

27+
(module+ test
28+
(require rackunit))
29+
2730
(define/contract (boolean->symbol b)
2831
(-> boolean? symbol?)
2932
(if b 'true 'false))
@@ -195,7 +198,9 @@
195198
(-> chkupdate? string?)
196199
(spec-entry->string
197200
"CHKUPDATE"
198-
(format "~a::~a" (chkupdate-type chkupdate) (chkupdate-value chkupdate))))
201+
(format "~a::~a" (chkupdate-type chkupdate) (chkupdate-value chkupdate))
202+
'any
203+
#t))
199204

200205
;; Whole `spec` file struct
201206
(struct spec-type (ver rel srcs subdir chksums chkupdate dummysrc?)
@@ -265,3 +270,174 @@
265270
(number->string (boolean->exact-nonnegative-integer
266271
(spec-type-dummysrc? spec))))
267272
out)))
273+
274+
(module+ test
275+
(require rackunit/text-ui)
276+
(define spec-tests
277+
(test-suite "SPEC tests"
278+
(test-suite "SRCS options tests"
279+
(check-equal? (branch "next")
280+
(src-option 'branch "next")
281+
"branch option")
282+
283+
(check-equal? (commit "4ad8776a633")
284+
(src-option 'commit "4ad8776a633")
285+
"commit option")
286+
287+
(check-equal? (rename "out") (src-option 'rename "out") "rename option")
288+
289+
(check-equal? (submodule #t)
290+
(src-option 'submodule 'true)
291+
"submodule option: true")
292+
(check-equal? (submodule #f)
293+
(src-option 'submodule 'false)
294+
"submodule option: false")
295+
(check-equal? (submodule 'recursive)
296+
(src-option 'submodule 'recursive)
297+
"submodule option: recursive")
298+
(check-exn exn:fail:contract?
299+
(λ () (submodule 'huh))
300+
"MUST FAIL submodule option: unknown symbol")
301+
302+
(check-equal? (copy-repo? #t)
303+
(src-option 'copy-repo 'true)
304+
"copy-repo option"))
305+
306+
(test-suite "SRCS Git SRC tests"
307+
(check-equal?
308+
(git "https://github.com/NVIDIA/nvidia-settings")
309+
(src 'git null "https://github.com/NVIDIA/nvidia-settings")
310+
"SRCS git no options")
311+
(check-equal? (git "https://github.com/NVIDIA/nvidia-settings"
312+
#:options
313+
(list (copy-repo? #t)
314+
(rename "nvidia")
315+
(commit (string-append "tags/v" "0.0.1"))
316+
(submodule 'recursive)))
317+
(src 'git
318+
(list (copy-repo? #t)
319+
(rename "nvidia")
320+
(commit (string-append "tags/v" "0.0.1"))
321+
(submodule 'recursive))
322+
"https://github.com/NVIDIA/nvidia-settings")
323+
"SRCS git with options")
324+
325+
(check-equal?
326+
(src->string (git "https://github.com/NVIDIA/nvidia-settings"))
327+
"git::https://github.com/NVIDIA/nvidia-settings"
328+
"SRCS ->string git no options")
329+
(check-equal?
330+
(src->string (git "https://github.com/NVIDIA/nvidia-settings"
331+
#:options
332+
(list (copy-repo? #t)
333+
(rename "nvidia")
334+
(commit (string-append "tags/v" "0.0.1"))
335+
(submodule 'recursive))))
336+
"git::copy-repo=true;rename=nvidia;commit=tags/v0.0.1;submodule=recursive::https://github.com/NVIDIA/nvidia-settings"
337+
"SRCS ->string git with options"))
338+
339+
(test-suite "SRCS Tarball SRC tests"
340+
(check-exn
341+
exn:fail:user?
342+
(λ ()
343+
(tbl
344+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
345+
#:options (list (copy-repo? #t)
346+
(rename "racket")
347+
(commit (string-append "tags/v" "0.0.1"))
348+
(submodule 'recursive))))
349+
"MUST FAIL SRCS tbl with illegal options")
350+
(check-equal?
351+
(tbl
352+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
353+
#:options (list (rename "racket")))
354+
(src
355+
'tbl
356+
(list (rename "racket"))
357+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz")
358+
"SRCS tbl with options")
359+
(check-equal?
360+
(tbl
361+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz")
362+
(src
363+
'tbl
364+
null
365+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz")
366+
"SRCS tbl no options")
367+
368+
(check-equal?
369+
(src->string
370+
(tbl
371+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"))
372+
"tbl::https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
373+
"SRCS ->string tbl no options")
374+
(check-equal?
375+
(src->string
376+
(tbl
377+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
378+
#:options (list (rename "racket"))))
379+
"tbl::rename=racket::https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
380+
"SRCS ->string tbl with options"))
381+
382+
(check-equal?
383+
(srcs->string
384+
(list
385+
(tbl
386+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
387+
#:options (list (rename "racket")))
388+
(git "https://github.com/NVIDIA/nvidia-settings"
389+
#:options (list (copy-repo? #t)
390+
(rename "nvidia")
391+
(commit (string-append "tags/v" "0.0.1"))
392+
(submodule 'recursive)))))
393+
"SRCS=\"tbl::rename=racket::https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz git::copy-repo=true;rename=nvidia;commit=tags/v0.0.1;submodule=recursive::https://github.com/NVIDIA/nvidia-settings\""
394+
"SRCS ->string")
395+
396+
(check-equal?
397+
(srcs->string
398+
(list
399+
(tbl
400+
"https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz"
401+
#:options (list (rename "racket")))
402+
(git "https://github.com/NVIDIA/nvidia-settings"
403+
#:options (list (copy-repo? #t)
404+
(rename "nvidia")
405+
(commit (string-append "tags/v" "0.0.1"))
406+
(submodule 'recursive))))
407+
'amd64)
408+
"SRCS__AMD64=\"tbl::rename=racket::https://download.racket-lang.org/releases/8.15/installers/racket-8.15-src.tgz git::copy-repo=true;rename=nvidia;commit=tags/v0.0.1;submodule=recursive::https://github.com/NVIDIA/nvidia-settings\""
409+
"SRCS ->string with ARCH")
410+
411+
(test-suite "CHKSUMS tests"
412+
(check-equal?
413+
(chksums->string
414+
(list
415+
(skip)
416+
(checksum
417+
'sha256
418+
"4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33")))
419+
"CHKSUMS=\"SKIP sha256::4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33\""
420+
"CHKSUMS ->string")
421+
422+
(check-equal?
423+
(chksums->string
424+
(list
425+
(skip)
426+
(checksum
427+
'sha256
428+
"4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33"))
429+
'amd64)
430+
"CHKSUMS__AMD64=\"SKIP sha256::4ccdbbd95d4aef058502c8ee07b1abb490f5ef4a4d6ff711440facd0b8eded33\""
431+
"CHKSUMS ->string with ARCH"))
432+
433+
(test-suite "CHKUPDATE tests"
434+
(check-equal?
435+
(chkupdate->string (gitlab "OriginCode/aosc-racket"
436+
"https://factoria.origincode.me"
437+
"\\d+\\.\\d+\\.\\d+"
438+
#t))
439+
"CHKUPDATE=\"gitlab::repo=OriginCode/aosc-racket;instance=https://factoria.origincode.me;pattern=\\d+\\.\\d+\\.\\d+;sort_version=true\""
440+
"CHKUPDATE ->string GitLab"))
441+
))
442+
443+
(run-tests spec-tests))

0 commit comments

Comments
 (0)