|
| 1 | +# This package provides `tectonic.passthru.tests`. |
| 2 | +# It requires internet access to fetch tectonic's resource bundle on demand. |
| 3 | + |
| 4 | +{ lib |
| 5 | +, fetchFromGitHub |
| 6 | +, runCommand |
| 7 | +, tectonic |
| 8 | +, curl |
| 9 | +, cacert |
| 10 | +, emptyFile |
| 11 | +}: |
| 12 | + |
| 13 | +let |
| 14 | + /* |
| 15 | + Currently, the test files are only fully available from the `dev` branch of |
| 16 | + `biber`. When https://github.com/plk/biber/pull/467 is eventually released, |
| 17 | + we can obtain the test files from `texlive.pkgs.biber.texsource`. For now, |
| 18 | + i.e. biber<=2.19, we fetch the test files directly from GitHub. |
| 19 | + */ |
| 20 | + biber-dev-source = fetchFromGitHub { |
| 21 | + owner = "plk"; |
| 22 | + repo = "biber"; |
| 23 | + # curl https://api.github.com/repos/plk/biber/pulls/467 | jq .merge_commit_sha |
| 24 | + rev = "d43e352586f5c9f98f0331978ca9d0b908986e09"; |
| 25 | + hash = "sha256-Z5BdMteBouiDQasF6GZXkS//YzrZkcX1eLvKIQIBkBs="; |
| 26 | + }; |
| 27 | + testfiles = "${biber-dev-source}/testfiles"; |
| 28 | + |
| 29 | + noNetNotice = builtins.toFile "tectonic-offline-notice" '' |
| 30 | + # To fetch tectonic's web bundle, the tests require internet access, |
| 31 | + # which is not available in the current environment. |
| 32 | + ''; |
| 33 | + # `cacert` is required for tls connections |
| 34 | + buildInputs = [ curl cacert tectonic ]; |
| 35 | + checkInternet = '' |
| 36 | + if curl --head "bing.com"; then |
| 37 | + set -e # continue to the tests defined below, fail on error |
| 38 | + else |
| 39 | + cat "${noNetNotice}" |
| 40 | + cp "${emptyFile}" "$out" |
| 41 | + exit # bail out gracefully when there is no internet, do not panic |
| 42 | + fi |
| 43 | + ''; |
| 44 | + |
| 45 | + fixedOutputTest = name: script: runCommand |
| 46 | + /* |
| 47 | + Introduce dependence on `tectonic` in the test package name. |
| 48 | + Note that adding `tectonic` to `buildInputs` is not enough to trigger |
| 49 | + rebuilds for a fixed-output derivation. One must update its name or |
| 50 | + output hash to induce a rebuild. This behavior is exactly the same as a |
| 51 | + standard nixpkgs "fetcher" such as `fetchurl`. |
| 52 | + */ |
| 53 | + "test-${lib.removePrefix "${builtins.storeDir}/" tectonic.outPath}-${name}" |
| 54 | + { |
| 55 | + /* |
| 56 | + Make a fixed-output derivation, return an `emptyFile` with fixed hash. |
| 57 | + These derivations are allowed to access the internet from within a |
| 58 | + sandbox, which allows us to test the automatic download of resource |
| 59 | + files in tectonic, as a side effect. The `tectonic.outPath` is included |
| 60 | + in `name` to induce rebuild of this fixed-output derivation whenever |
| 61 | + the `tectonic` derivation is updated. |
| 62 | + */ |
| 63 | + inherit (emptyFile) |
| 64 | + outputHashAlgo |
| 65 | + outputHashMode |
| 66 | + outputHash |
| 67 | + ; |
| 68 | + preferLocalBuild = true; |
| 69 | + allowSubstitutes = false; |
| 70 | + inherit buildInputs; |
| 71 | + } |
| 72 | + '' |
| 73 | + ${checkInternet} |
| 74 | + ${script} |
| 75 | + cp "${emptyFile}" "$out" |
| 76 | + ''; |
| 77 | + |
| 78 | +in |
| 79 | +lib.mapAttrs fixedOutputTest { |
| 80 | + biber = '' |
| 81 | + # import the test files |
| 82 | + cp "${testfiles}"/* . |
| 83 | +
|
| 84 | + # tectonic caches in the $HOME directory, so set it to $PWD |
| 85 | + export HOME=$PWD |
| 86 | + tectonic -X compile ./test.tex |
| 87 | + ''; |
| 88 | +} |
0 commit comments