diff options
| author | Phillip Davis <phdavis1027@gmail.com> | 2026-03-19 12:18:11 -0400 |
|---|---|---|
| committer | Nguyễn Gia Phong <cnx@loang.net> | 2026-05-26 00:09:12 +0900 |
| commit | 3df17cb25a96f53cc12a2094320f73c02c1f19e1 (patch) | |
| tree | 5c91a64c6582ec1dba2079702851c6ca02a16ba2 /tests | |
| parent | abbf03a2efb4a8f3863ba5860e25657a557ea743 (diff) | |
import: gem: Use spdx-string->license for license lookup.
Similar to what was done for the crate importer in 263a267b75.
* guix/import/gem.scm (string->license): Try spdx-string->license first,
returning symbols instead of license objects. Fall back
to the existing hardcoded table for non-SPDX strings.
(make-gem-sexp): Remove license->symbol calls;
licenses are now symbols directly.
* tests/import/gem.scm (test-spdx-json): New fixture.
("gem->guix-package with SPDX license identifiers"): New test.
Change-Id: I5fa0ebdfd3a3393eab5ef0554ed09887a89bc107
Reviewed-by: Carlo Zancanaro <carlo@zancanaro.id.au>
Signed-off-by: Nguyễn Gia Phong <cnx@loang.net>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/import/gem.scm | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/import/gem.scm b/tests/import/gem.scm index dfa33d40366..9b65c328ca9 100644 --- a/tests/import/gem.scm +++ b/tests/import/gem.scm | |||
| @@ -125,6 +125,19 @@ | |||
| 125 | \"licenses\": [\"MIT\"] | 125 | \"licenses\": [\"MIT\"] |
| 126 | }") | 126 | }") |
| 127 | 127 | ||
| 128 | (define test-spdx-json | ||
| 129 | "{ | ||
| 130 | \"name\": \"spdx-gem\", | ||
| 131 | \"version\": \"1.0.0\", | ||
| 132 | \"sha\": \"f3676eafca9987cb5fe263df1edf2538bf6dafc712b30e17be3543a9680547a8\", | ||
| 133 | \"info\": \"A gem with SPDX licenses\", | ||
| 134 | \"homepage_uri\": \"https://example.com\", | ||
| 135 | \"dependencies\": { | ||
| 136 | \"runtime\": [] | ||
| 137 | }, | ||
| 138 | \"licenses\": [\"Ruby\", \"BSD-2-Clause\"] | ||
| 139 | }") | ||
| 140 | |||
| 128 | (test-begin "gem") | 141 | (test-begin "gem") |
| 129 | 142 | ||
| 130 | (test-assert "gem->guix-package" | 143 | (test-assert "gem->guix-package" |
| @@ -346,4 +359,85 @@ | |||
| 346 | (x | 359 | (x |
| 347 | (pk 'fail x #f))))) | 360 | (pk 'fail x #f))))) |
| 348 | 361 | ||
| 362 | (test-assert "gem->guix-package with SPDX license identifiers" | ||
| 363 | (mock ((guix http-client) http-fetch | ||
| 364 | (lambda (url . rest) | ||
| 365 | (match url | ||
| 366 | ("https://rubygems.org/api/v1/gems/spdx-gem.json" | ||
| 367 | (values (open-input-string test-spdx-json) | ||
| 368 | (string-length test-spdx-json))) | ||
| 369 | (_ (error "Unexpected URL: " url))))) | ||
| 370 | (match (gem->guix-package "spdx-gem") | ||
| 371 | (`(package | ||
| 372 | (name "ruby-spdx-gem") | ||
| 373 | (version "1.0.0") | ||
| 374 | (source (origin | ||
| 375 | (method url-fetch) | ||
| 376 | (uri (rubygems-uri "spdx-gem" version)) | ||
| 377 | (sha256 | ||
| 378 | (base32 | ||
| 379 | "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk")))) | ||
| 380 | (build-system ruby-build-system) | ||
| 381 | (synopsis "A gem with SPDX licenses") | ||
| 382 | (description "This package provides a gem with SPDX licenses.") | ||
| 383 | (home-page "https://example.com") | ||
| 384 | (license (list license:ruby license:bsd-2))) | ||
| 385 | #t) | ||
| 386 | (x | ||
| 387 | (pk 'fail x #f))))) | ||
| 388 | |||
| 389 | (test-assert "gem->guix-package with gibberish license identifiers" | ||
| 390 | (mock ((guix http-client) http-fetch | ||
| 391 | (lambda (url . rest) | ||
| 392 | (match url | ||
| 393 | ("https://rubygems.org/api/v1/gems/gibberish-license-gem.json" | ||
| 394 | (values (open-input-string test-gibberish-licenses-json) | ||
| 395 | (string-length test-gibberish-licenses-json))) | ||
| 396 | (_ (error "Unexpected URL: " url))))) | ||
| 397 | (match (gem->guix-package "gibberish-license-gem") | ||
| 398 | (`(package | ||
| 399 | (name "ruby-gibberish-license-gem") | ||
| 400 | (version "1.0.0") | ||
| 401 | (source (origin | ||
| 402 | (method url-fetch) | ||
| 403 | (uri (rubygems-uri "gibberish-license-gem" version)) | ||
| 404 | (sha256 | ||
| 405 | (base32 | ||
| 406 | "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk")))) | ||
| 407 | (build-system ruby-build-system) | ||
| 408 | (synopsis "A gem with gibberish licenses") | ||
| 409 | (description "This package provides a gem with gibberish licenses.") | ||
| 410 | (home-page "https://example.com") | ||
| 411 | (license (list unknown-license! unknown-license!))) | ||
| 412 | #t) | ||
| 413 | (x | ||
| 414 | (pk 'fail x #f))))) | ||
| 415 | |||
| 416 | (test-assert "gem->guix-package with mixed valid and gibberish licenses" | ||
| 417 | (mock ((guix http-client) http-fetch | ||
| 418 | (lambda (url . rest) | ||
| 419 | (match url | ||
| 420 | ("https://rubygems.org/api/v1/gems/mixed-license-gem.json" | ||
| 421 | (values (open-input-string test-mixed-licenses-json) | ||
| 422 | (string-length test-mixed-licenses-json))) | ||
| 423 | (_ (error "Unexpected URL: " url))))) | ||
| 424 | (match (gem->guix-package "mixed-license-gem") | ||
| 425 | (`(package | ||
| 426 | (name "ruby-mixed-license-gem") | ||
| 427 | (version "1.0.0") | ||
| 428 | (source (origin | ||
| 429 | (method url-fetch) | ||
| 430 | (uri (rubygems-uri "mixed-license-gem" version)) | ||
| 431 | (sha256 | ||
| 432 | (base32 | ||
| 433 | "1a270mlajhrmpqbhxcqjqypnvgrq4pgixpv3w9gwp1wrrapnwrzk")))) | ||
| 434 | (build-system ruby-build-system) | ||
| 435 | (synopsis "A gem with one valid and one gibberish license") | ||
| 436 | (description "This package provides a gem with one valid \ | ||
| 437 | and one gibberish license.") | ||
| 438 | (home-page "https://example.com") | ||
| 439 | (license (list license:expat unknown-license!))) | ||
| 440 | #t) | ||
| 441 | (x | ||
| 442 | (pk 'fail x #f))))) | ||
| 349 | (test-end "gem") | 443 | (test-end "gem") |
