crate.scm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2014 David Thompson <davet@gnu.org>
  3. ;;; Copyright © 2016 David Craven <david@craven.ch>
  4. ;;; Copyright © 2019, 2020, 2022 Ludovic Courtès <ludo@gnu.org>
  5. ;;; Copyright © 2020 Martin Becze <mjbecze@riseup.net>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (test-crate)
  22. #:use-module (guix import crate)
  23. #:use-module (guix base32)
  24. #:use-module (guix build-system cargo)
  25. #:use-module (gcrypt hash)
  26. #:use-module (guix tests)
  27. #:use-module (gnu packages)
  28. #:use-module (ice-9 iconv)
  29. #:use-module (ice-9 match)
  30. #:use-module (srfi srfi-64))
  31. ;; crate versions and dependencies used here
  32. ;; foo-0.8.1
  33. ;; foo-1.0.0
  34. ;; foo-1.0.3
  35. ;; leaf-alice 0.7.5
  36. ;;
  37. ;; root-1.0.0
  38. ;; root-1.0.4
  39. ;; intermediate-a 1.0.42
  40. ;; intermeidate-b ^1.0.0
  41. ;; leaf-alice ^0.7
  42. ;; leaf-bob ^3
  43. ;;
  44. ;; intermediate-a-1.0.40
  45. ;; intermediate-a-1.0.42
  46. ;; intermediate-a-1.1.0-alpha.1
  47. ;; intermediate-a 1.2.3
  48. ;; leaf-alice 0.7.5
  49. ;; leaf-bob ^3
  50. ;;
  51. ;; intermediate-b-1.2.3
  52. ;; leaf-bob 3.0.1
  53. ;;
  54. ;; leaf-alice-0.7.3
  55. ;; leaf-alice-0.7.5
  56. ;;
  57. ;; leaf-bob-3.0.1
  58. (define test-foo-crate
  59. "{
  60. \"crate\": {
  61. \"max_version\": \"1.0.3\",
  62. \"name\": \"foo\",
  63. \"description\": \"summary\",
  64. \"homepage\": \"http://example.com\",
  65. \"repository\": \"http://example.com\",
  66. \"keywords\": [\"dummy\", \"test\"],
  67. \"categories\": [\"test\"],
  68. \"actual_versions\": [
  69. { \"id\": 234210,
  70. \"num\": \"0.8.1\",
  71. \"license\": \"MIT OR Apache-2.0\",
  72. \"links\": {
  73. \"dependencies\": \"/api/v1/crates/foo/0.8.1/dependencies\"
  74. }
  75. },
  76. { \"id\": 234212,
  77. \"num\": \"1.0.0\",
  78. \"license\": \"MIT OR Apache-2.0\",
  79. \"links\": {
  80. \"dependencies\": \"/api/v1/crates/foo/1.0.0/dependencies\"
  81. }
  82. },
  83. { \"id\": 234214,
  84. \"num\": \"1.0.3\",
  85. \"license\": \"MIT OR Apache-2.0\",
  86. \"links\": {
  87. \"dependencies\": \"/api/v1/crates/foo/1.0.3/dependencies\"
  88. }
  89. }
  90. ]
  91. }
  92. }")
  93. (define test-foo-dependencies
  94. "{
  95. \"dependencies\": [
  96. {
  97. \"crate_id\": \"leaf-alice\",
  98. \"kind\": \"normal\",
  99. \"req\": \"0.7.5\"
  100. }
  101. ]
  102. }")
  103. (define test-root-crate
  104. "{
  105. \"crate\": {
  106. \"max_version\": \"1.0.4\",
  107. \"name\": \"root\",
  108. \"description\": \"summary\",
  109. \"homepage\": \"http://example.com\",
  110. \"repository\": \"http://example.com\",
  111. \"keywords\": [\"dummy\", \"test\"],
  112. \"categories\": [\"test\"],
  113. \"actual_versions\": [
  114. { \"id\": 234240,
  115. \"num\": \"1.0.0\",
  116. \"license\": \"MIT OR Apache-2.0\",
  117. \"links\": {
  118. \"dependencies\": \"/api/v1/crates/root/1.0.0/dependencies\"
  119. }
  120. },
  121. { \"id\": 234242,
  122. \"num\": \"1.0.4\",
  123. \"license\": \"MIT OR Apache-2.0\",
  124. \"links\": {
  125. \"dependencies\": \"/api/v1/crates/root/1.0.4/dependencies\"
  126. }
  127. }
  128. ]
  129. }
  130. }")
  131. (define test-root-dependencies
  132. "{
  133. \"dependencies\": [
  134. {
  135. \"crate_id\": \"intermediate-a\",
  136. \"kind\": \"normal\",
  137. \"req\": \"1.0.42\"
  138. },
  139. {
  140. \"crate_id\": \"intermediate-b\",
  141. \"kind\": \"normal\",
  142. \"req\": \"^1.0.0\"
  143. },
  144. {
  145. \"crate_id\": \"leaf-alice\",
  146. \"kind\": \"normal\",
  147. \"req\": \"^0.7\"
  148. },
  149. {
  150. \"crate_id\": \"leaf-bob\",
  151. \"kind\": \"normal\",
  152. \"req\": \"^3\"
  153. }
  154. ]
  155. }")
  156. (define test-intermediate-a-crate
  157. "{
  158. \"crate\": {
  159. \"max_version\": \"1.1.0-alpha.1\",
  160. \"name\": \"intermediate-a\",
  161. \"description\": \"summary\",
  162. \"homepage\": \"http://example.com\",
  163. \"repository\": \"http://example.com\",
  164. \"keywords\": [\"dummy\", \"test\"],
  165. \"categories\": [\"test\"],
  166. \"actual_versions\": [
  167. { \"id\": 234251,
  168. \"num\": \"1.0.40\",
  169. \"license\": \"MIT OR Apache-2.0\",
  170. \"links\": {
  171. \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.40/dependencies\"
  172. }
  173. },
  174. { \"id\": 234250,
  175. \"num\": \"1.0.42\",
  176. \"license\": \"MIT OR Apache-2.0\",
  177. \"links\": {
  178. \"dependencies\": \"/api/v1/crates/intermediate-a/1.0.42/dependencies\"
  179. }
  180. },
  181. { \"id\": 234252,
  182. \"num\": \"1.1.0-alpha.1\",
  183. \"license\": \"MIT OR Apache-2.0\",
  184. \"links\": {
  185. \"dependencies\": \"/api/v1/crates/intermediate-a/1.1.0-alpha.1/dependencies\"
  186. }
  187. }
  188. ]
  189. }
  190. }")
  191. (define test-intermediate-a-dependencies
  192. "{
  193. \"dependencies\": [
  194. {
  195. \"crate_id\": \"intermediate-b\",
  196. \"kind\": \"normal\",
  197. \"req\": \"1.2.3\"
  198. },
  199. {
  200. \"crate_id\": \"leaf-alice\",
  201. \"kind\": \"normal\",
  202. \"req\": \"0.7.5\"
  203. },
  204. {
  205. \"crate_id\": \"leaf-bob\",
  206. \"kind\": \"normal\",
  207. \"req\": \"^3\"
  208. }
  209. ]
  210. }")
  211. (define test-intermediate-b-crate
  212. "{
  213. \"crate\": {
  214. \"max_version\": \"1.2.3\",
  215. \"name\": \"intermediate-b\",
  216. \"description\": \"summary\",
  217. \"homepage\": \"http://example.com\",
  218. \"repository\": \"http://example.com\",
  219. \"keywords\": [\"dummy\", \"test\"],
  220. \"categories\": [\"test\"],
  221. \"actual_versions\": [
  222. { \"id\": 234260,
  223. \"num\": \"1.2.3\",
  224. \"license\": \"MIT OR Apache-2.0\",
  225. \"links\": {
  226. \"dependencies\": \"/api/v1/crates/intermediate-b/1.2.3/dependencies\"
  227. }
  228. }
  229. ]
  230. }
  231. }")
  232. (define test-intermediate-b-dependencies
  233. "{
  234. \"dependencies\": [
  235. {
  236. \"crate_id\": \"leaf-bob\",
  237. \"kind\": \"normal\",
  238. \"req\": \"3.0.1\"
  239. }
  240. ]
  241. }")
  242. (define test-leaf-alice-crate
  243. "{
  244. \"crate\": {
  245. \"max_version\": \"0.7.5\",
  246. \"name\": \"leaf-alice\",
  247. \"description\": \"summary\",
  248. \"homepage\": \"http://example.com\",
  249. \"repository\": \"http://example.com\",
  250. \"keywords\": [\"dummy\", \"test\"],
  251. \"categories\": [\"test\"],
  252. \"actual_versions\": [
  253. { \"id\": 234270,
  254. \"num\": \"0.7.3\",
  255. \"license\": \"MIT OR Apache-2.0\",
  256. \"links\": {
  257. \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.3/dependencies\"
  258. }
  259. },
  260. { \"id\": 234272,
  261. \"num\": \"0.7.5\",
  262. \"license\": \"MIT OR Apache-2.0\",
  263. \"links\": {
  264. \"dependencies\": \"/api/v1/crates/leaf-alice/0.7.5/dependencies\"
  265. }
  266. }
  267. ]
  268. }
  269. }")
  270. (define test-leaf-alice-dependencies
  271. "{
  272. \"dependencies\": []
  273. }")
  274. (define test-leaf-bob-crate
  275. "{
  276. \"crate\": {
  277. \"max_version\": \"3.0.1\",
  278. \"name\": \"leaf-bob\",
  279. \"description\": \"summary\",
  280. \"homepage\": \"http://example.com\",
  281. \"repository\": \"http://example.com\",
  282. \"keywords\": [\"dummy\", \"test\"],
  283. \"categories\": [\"test\"]
  284. \"actual_versions\": [
  285. { \"id\": 234280,
  286. \"num\": \"3.0.1\",
  287. \"license\": \"MIT OR Apache-2.0\",
  288. \"links\": {
  289. \"dependencies\": \"/api/v1/crates/leaf-bob/3.0.1/dependencies\"
  290. }
  291. }
  292. ]
  293. }
  294. }")
  295. (define test-leaf-bob-dependencies
  296. "{
  297. \"dependencies\": []
  298. }")
  299. (define test-source-hash
  300. "")
  301. (define have-guile-semver?
  302. (false-if-exception (resolve-interface '(semver))))
  303. (test-begin "crate")
  304. (test-equal "guix-package->crate-name"
  305. "rustc-serialize"
  306. (guix-package->crate-name
  307. (dummy-package
  308. "rust-rustc-serialize"
  309. (source (dummy-origin
  310. (uri (crate-uri "rustc-serialize" "1.0")))))))
  311. (unless have-guile-semver? (test-skip 1))
  312. (test-assert "crate->guix-package"
  313. ;; Replace network resources with sample data.
  314. (mock ((guix http-client) http-fetch
  315. (lambda (url . rest)
  316. (match url
  317. ("https://crates.io/api/v1/crates/foo"
  318. (open-input-string test-foo-crate))
  319. ("https://crates.io/api/v1/crates/foo/1.0.3/download"
  320. (set! test-source-hash
  321. (bytevector->nix-base32-string
  322. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  323. (open-input-string "empty file\n"))
  324. ("https://crates.io/api/v1/crates/foo/1.0.3/dependencies"
  325. (open-input-string test-foo-dependencies))
  326. ("https://crates.io/api/v1/crates/leaf-alice"
  327. (open-input-string test-leaf-alice-crate))
  328. ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
  329. (set! test-source-hash
  330. (bytevector->nix-base32-string
  331. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  332. (open-input-string "empty file\n"))
  333. ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
  334. (open-input-string test-leaf-alice-dependencies))
  335. (_ (error "Unexpected URL: " url)))))
  336. (match (crate->guix-package "foo")
  337. ((define-public 'rust-foo-1
  338. (package (name "rust-foo")
  339. (version "1.0.3")
  340. (source
  341. (origin
  342. (method url-fetch)
  343. (uri (crate-uri "foo" 'version))
  344. (file-name (string-append name "-" version ".tar.gz"))
  345. (sha256
  346. (base32
  347. (? string? hash)))))
  348. (build-system 'cargo-build-system)
  349. (arguments
  350. ('quasiquote
  351. (#:skip-build? #t
  352. #:cargo-inputs
  353. (("rust-leaf-alice" ('unquote 'rust-leaf-alice-0.7))))))
  354. (home-page "http://example.com")
  355. (synopsis "summary")
  356. (description "summary")
  357. (license (list license:expat license:asl2.0))))
  358. (string=? test-source-hash hash))
  359. (x
  360. (pk 'fail x #f)))))
  361. (unless have-guile-semver? (test-skip 1))
  362. (test-assert "cargo-recursive-import"
  363. ;; Replace network resources with sample data.
  364. (mock ((guix http-client) http-fetch
  365. (lambda (url . rest)
  366. (match url
  367. ("https://crates.io/api/v1/crates/root"
  368. (open-input-string test-root-crate))
  369. ("https://crates.io/api/v1/crates/root/1.0.4/download"
  370. (set! test-source-hash
  371. (bytevector->nix-base32-string
  372. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  373. (open-input-string "empty file\n"))
  374. ("https://crates.io/api/v1/crates/root/1.0.4/dependencies"
  375. (open-input-string test-root-dependencies))
  376. ("https://crates.io/api/v1/crates/intermediate-a"
  377. (open-input-string test-intermediate-a-crate))
  378. ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/download"
  379. (set! test-source-hash
  380. (bytevector->nix-base32-string
  381. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  382. (open-input-string "empty file\n"))
  383. ("https://crates.io/api/v1/crates/intermediate-a/1.0.42/dependencies"
  384. (open-input-string test-intermediate-a-dependencies))
  385. ("https://crates.io/api/v1/crates/intermediate-b"
  386. (open-input-string test-intermediate-b-crate))
  387. ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/download"
  388. (set! test-source-hash
  389. (bytevector->nix-base32-string
  390. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  391. (open-input-string "empty file\n"))
  392. ("https://crates.io/api/v1/crates/intermediate-b/1.2.3/dependencies"
  393. (open-input-string test-intermediate-b-dependencies))
  394. ("https://crates.io/api/v1/crates/leaf-alice"
  395. (open-input-string test-leaf-alice-crate))
  396. ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/download"
  397. (set! test-source-hash
  398. (bytevector->nix-base32-string
  399. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  400. (open-input-string "empty file\n"))
  401. ("https://crates.io/api/v1/crates/leaf-alice/0.7.5/dependencies"
  402. (open-input-string test-leaf-alice-dependencies))
  403. ("https://crates.io/api/v1/crates/leaf-bob"
  404. (open-input-string test-leaf-bob-crate))
  405. ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/download"
  406. (set! test-source-hash
  407. (bytevector->nix-base32-string
  408. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  409. (open-input-string "empty file\n"))
  410. ("https://crates.io/api/v1/crates/leaf-bob/3.0.1/dependencies"
  411. (open-input-string test-leaf-bob-dependencies))
  412. (_ (error "Unexpected URL: " url)))))
  413. (match (crate-recursive-import "root")
  414. ;; rust-intermediate-b has no dependency on the rust-leaf-alice
  415. ;; package, so this is a valid ordering
  416. (((define-public 'rust-leaf-alice-0.7
  417. (package
  418. (name "rust-leaf-alice")
  419. (version "0.7.5")
  420. (source
  421. (origin
  422. (method url-fetch)
  423. (uri (crate-uri "leaf-alice" version))
  424. (file-name
  425. (string-append name "-" version ".tar.gz"))
  426. (sha256
  427. (base32
  428. (? string? hash)))))
  429. (build-system cargo-build-system)
  430. (arguments ('quasiquote (#:skip-build? #t)))
  431. (home-page "http://example.com")
  432. (synopsis "summary")
  433. (description "summary")
  434. (license (list license:expat license:asl2.0))))
  435. (define-public 'rust-leaf-bob-3
  436. (package
  437. (name "rust-leaf-bob")
  438. (version "3.0.1")
  439. (source
  440. (origin
  441. (method url-fetch)
  442. (uri (crate-uri "leaf-bob" version))
  443. (file-name
  444. (string-append name "-" version ".tar.gz"))
  445. (sha256
  446. (base32
  447. (? string? hash)))))
  448. (build-system cargo-build-system)
  449. (arguments ('quasiquote (#:skip-build? #t)))
  450. (home-page "http://example.com")
  451. (synopsis "summary")
  452. (description "summary")
  453. (license (list license:expat license:asl2.0))))
  454. (define-public 'rust-intermediate-b-1
  455. (package
  456. (name "rust-intermediate-b")
  457. (version "1.2.3")
  458. (source
  459. (origin
  460. (method url-fetch)
  461. (uri (crate-uri "intermediate-b" version))
  462. (file-name
  463. (string-append name "-" version ".tar.gz"))
  464. (sha256
  465. (base32
  466. (? string? hash)))))
  467. (build-system cargo-build-system)
  468. (arguments
  469. ('quasiquote (#:skip-build? #t
  470. #:cargo-inputs
  471. (("rust-leaf-bob"
  472. ('unquote rust-leaf-bob-3))))))
  473. (home-page "http://example.com")
  474. (synopsis "summary")
  475. (description "summary")
  476. (license (list license:expat license:asl2.0))))
  477. (define-public 'rust-intermediate-a-1
  478. (package
  479. (name "rust-intermediate-a")
  480. (version "1.0.42")
  481. (source
  482. (origin
  483. (method url-fetch)
  484. (uri (crate-uri "intermediate-a" version))
  485. (file-name
  486. (string-append name "-" version ".tar.gz"))
  487. (sha256
  488. (base32
  489. (? string? hash)))))
  490. (build-system cargo-build-system)
  491. (arguments
  492. ('quasiquote (#:skip-build? #t
  493. #:cargo-inputs
  494. (("rust-intermediate-b"
  495. ('unquote rust-intermediate-b-1))
  496. ("rust-leaf-alice"
  497. ('unquote 'rust-leaf-alice-0.7))
  498. ("rust-leaf-bob"
  499. ('unquote rust-leaf-bob-3))))))
  500. (home-page "http://example.com")
  501. (synopsis "summary")
  502. (description "summary")
  503. (license (list license:expat license:asl2.0))))
  504. (define-public 'rust-root-1
  505. (package
  506. (name "rust-root")
  507. (version "1.0.4")
  508. (source
  509. (origin
  510. (method url-fetch)
  511. (uri (crate-uri "root" version))
  512. (file-name
  513. (string-append name "-" version ".tar.gz"))
  514. (sha256
  515. (base32
  516. (? string? hash)))))
  517. (build-system cargo-build-system)
  518. (arguments
  519. ('quasiquote (#:cargo-inputs
  520. (("rust-intermediate-a"
  521. ('unquote rust-intermediate-a-1))
  522. ("rust-intermediate-b"
  523. ('unquote rust-intermediate-b-1))
  524. ("rust-leaf-alice"
  525. ('unquote 'rust-leaf-alice-0.7))
  526. ("rust-leaf-bob"
  527. ('unquote rust-leaf-bob-3))))))
  528. (home-page "http://example.com")
  529. (synopsis "summary")
  530. (description "summary")
  531. (license (list license:expat license:asl2.0)))))
  532. #t)
  533. (x
  534. (pk 'fail x #f)))))
  535. (test-equal "licenses: MIT OR Apache-2.0"
  536. '(license:expat license:asl2.0)
  537. (string->license "MIT OR Apache-2.0"))
  538. (test-equal "licenses: Apache-2.0 / MIT"
  539. '(license:asl2.0 license:expat)
  540. (string->license "Apache-2.0 / MIT"))
  541. (test-equal "licenses: Apache-2.0 WITH LLVM-exception"
  542. '(license:asl2.0 unknown-license!)
  543. (string->license "Apache-2.0 WITH LLVM-exception"))
  544. (test-equal "licenses: MIT/Apache-2.0 AND BSD-2-Clause"
  545. '(license:expat license:asl2.0 license:bsd-2)
  546. (string->license "MIT/Apache-2.0 AND BSD-2-Clause"))
  547. (test-equal "licenses: MIT/Apache-2.0"
  548. '(license:expat license:asl2.0)
  549. (string->license "MIT/Apache-2.0"))
  550. (define test-doctool-crate
  551. "{
  552. \"crate\": {
  553. \"max_version\": \"2.2.2\",
  554. \"name\": \"leaf-bob\",
  555. \"description\": \"summary\",
  556. \"homepage\": \"http://example.com\",
  557. \"repository\": \"http://example.com\",
  558. \"keywords\": [\"dummy\", \"test\"],
  559. \"categories\": [\"test\"]
  560. \"actual_versions\": [
  561. { \"id\": 234280,
  562. \"num\": \"2.2.2\",
  563. \"license\": \"MIT OR Apache-2.0\",
  564. \"links\": {
  565. \"dependencies\": \"/api/v1/crates/doctool/2.2.2/dependencies\"
  566. }
  567. }
  568. ]
  569. }
  570. }")
  571. ;; FIXME: This test depends on some existing packages
  572. (define test-doctool-dependencies
  573. "{
  574. \"dependencies\": [
  575. {
  576. \"crate_id\": \"docopt\",
  577. \"kind\": \"normal\",
  578. \"req\": \"^0.8.1\"
  579. }
  580. ]
  581. }")
  582. (test-assert "self-test: rust-docopt 0.8.x is gone, please adjust the test case"
  583. (not (null? (find-packages-by-name "rust-docopt" "0.8"))))
  584. (unless have-guile-semver? (test-skip 1))
  585. (test-assert "cargo-recursive-import-hoors-existing-packages"
  586. (mock ((guix http-client) http-fetch
  587. (lambda (url . rest)
  588. (match url
  589. ("https://crates.io/api/v1/crates/doctool"
  590. (open-input-string test-doctool-crate))
  591. ("https://crates.io/api/v1/crates/doctool/2.2.2/download"
  592. (set! test-source-hash
  593. (bytevector->nix-base32-string
  594. (sha256 (string->bytevector "empty file\n" "utf-8"))))
  595. (open-input-string "empty file\n"))
  596. ("https://crates.io/api/v1/crates/doctool/2.2.2/dependencies"
  597. (open-input-string test-doctool-dependencies))
  598. (_ (error "Unexpected URL: " url)))))
  599. (match (crate-recursive-import "doctool")
  600. (((define-public 'rust-doctool-2
  601. (package
  602. (name "rust-doctool")
  603. (version "2.2.2")
  604. (source
  605. (origin
  606. (method url-fetch)
  607. (uri (crate-uri "doctool" version))
  608. (file-name
  609. (string-append name "-" version ".tar.gz"))
  610. (sha256
  611. (base32
  612. (? string? hash)))))
  613. (build-system cargo-build-system)
  614. (arguments
  615. ('quasiquote (#:cargo-inputs
  616. (("rust-docopt"
  617. ('unquote 'rust-docopt-0.8))))))
  618. (home-page "http://example.com")
  619. (synopsis "summary")
  620. (description "summary")
  621. (license (list license:expat license:asl2.0)))))
  622. #t)
  623. (x
  624. (pk 'fail x #f)))))
  625. (test-end "crate")