guix/tests
Eelco Dolstra c273c15cb1 Add primop ‘scopedImport’
‘scopedImport’ works like ‘import’, except that it takes a set of
attributes to be added to the lexical scope of the expression,
essentially extending or overriding the builtin variables.  For
instance, the expression

  scopedImport { x = 1; } ./foo.nix

where foo.nix contains ‘x’, will evaluate to 1.

This has a few applications:

* It allows getting rid of function argument specifications in package
  expressions. For instance, a package expression like:

    { stdenv, fetchurl, libfoo }:

    stdenv.mkDerivation { ... buildInputs = [ libfoo ]; }

  can now we written as just

    stdenv.mkDerivation { ... buildInputs = [ libfoo ]; }

  and imported in all-packages.nix as:

    bar = scopedImport pkgs ./bar.nix;

  So whereas we once had dependencies listed in three places
  (buildInputs, the function, and the call site), they now only need
  to appear in one place.

* It allows overriding builtin functions. For instance, to trace all
  calls to ‘map’:

  let
    overrides = {
      map = f: xs: builtins.trace "map called!" (map f xs);

      # Ensure that our override gets propagated by calls to
      # import/scopedImport.
      import = fn: scopedImport overrides fn;

      scopedImport = attrs: fn: scopedImport (overrides // attrs) fn;

      # Also update ‘builtins’.
      builtins = builtins // overrides;
    };
  in scopedImport overrides ./bla.nix

* Similarly, it allows extending the set of builtin functions. For
  instance, during Nixpkgs/NixOS evaluation, the Nixpkgs library
  functions could be added to the default scope.

There is a downside: calls to scopedImport are not memoized, unlike
import. So importing a file multiple times leads to multiple parsings
/ evaluations. It would be possible to construct the AST only once,
but that would require careful handling of variables/environments.
2014-05-26 14:26:29 +02:00
..
lang Add primop ‘scopedImport’ 2014-05-26 14:26:29 +02:00
add.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
binary-cache.sh Test executables in NARs 2014-02-26 18:59:01 +01:00
binary-patching.nix * Urgh, FreeBSD doesn't have a "seq" command. 2011-02-09 14:03:16 +00:00
binary-patching.sh nix-push: Support generating a manifest again 2012-07-26 18:28:12 -04:00
build-hook.hook.sh * Made the build hook mechanism more efficient. Rather than starting 2010-08-25 20:44:28 +00:00
build-hook.nix Fix test 2013-10-17 11:18:37 +02:00
build-hook.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
check-refs.nix
check-refs.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
common.sh.in Add a test for repairing paths 2014-02-17 12:22:50 +01:00
config.nix Add support for ‘make installcheck’ 2013-11-25 18:47:03 +01:00
dependencies.builder0.sh Test executables in NARs 2014-02-26 18:59:01 +01:00
dependencies.builder1.sh
dependencies.builder2.sh
dependencies.nix Test string semantics a bit more 2013-10-17 01:12:43 +02:00
dependencies.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
dump-db.sh Add a test for nix-store --dump-db / --load-db 2014-02-26 17:47:54 +01:00
export-graph.nix Support quoted attribute names in -A 2013-11-18 10:21:12 +00:00
export-graph.sh Support quoted attribute names in -A 2013-11-18 10:21:12 +00:00
export.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
fallback.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
fetchurl.nix Add a test for the fetchurl function 2012-07-09 15:41:43 -04:00
fetchurl.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
filter-source.nix
filter-source.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
fixed.builder1.sh
fixed.builder2.sh
fixed.nix
fixed.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
gc-concurrent.builder.sh
gc-concurrent.nix
gc-concurrent.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
gc-concurrent2.builder.sh
gc-runtime.nix
gc-runtime.sh Replace "make check" with "make installcheck" 2012-03-19 01:20:02 +01:00
gc.sh Test nix-store -q --roots 2014-02-26 18:00:46 +01:00
hash-check.nix
hash.sh Replace "make check" with "make installcheck" 2012-03-19 01:20:02 +01:00
import-derivation.nix * Add a test for importing derivations. 2012-01-26 13:04:50 +00:00
import-derivation.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
init.sh Fix Debian tests 2014-05-02 19:02:10 +02:00
install-package.sh nix-push: Support generating a manifest again 2012-07-26 18:28:12 -04:00
lang.sh Test trace and addErrorContext 2014-02-26 19:12:31 +01:00
local.mk Disable parallel.sh test 2014-05-22 11:38:50 +02:00
logging.sh Test nix-store -l 2014-02-26 17:58:53 +01:00
misc.sh nix-instantiate: Rename --eval-only to --eval, --parse-only to --parse 2014-02-19 16:34:24 +01:00
multiple-outputs.nix Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
multiple-outputs.sh Fix the multiple-outputs test 2012-11-26 17:46:45 +01:00
negative-caching.nix
negative-caching.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
nix-build.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
nix-channel.sh nix-push: Support generating a manifest again 2012-07-26 18:28:12 -04:00
nix-copy-closure.nix Fix test evaluation 2014-04-15 15:32:27 +02:00
nix-profile.sh Fix the nix-profile test 2014-02-01 15:37:50 +01:00
nix-pull.sh Fix test failure on Darwin 2012-09-12 11:29:10 -04:00
nix-push.sh nix-push: Support generating a manifest again 2012-07-26 18:28:12 -04:00
optimise-store.sh Test nix-store --optimise 2014-02-26 17:53:51 +01:00
parallel.builder.sh Drop dependency on ‘expr’ 2014-02-06 13:51:57 +01:00
parallel.nix
parallel.sh Add support for ‘make installcheck’ 2013-11-25 18:47:03 +01:00
referrers.sh Clean up a test warning 2014-02-06 13:54:44 +01:00
remote-builds.nix Fix test evaluation 2014-04-15 15:32:27 +02:00
remote-store.sh Doh 2014-02-26 22:41:29 +01:00
repair.sh Test nix-store --verify-path and --repair-path 2014-02-17 23:24:12 +01:00
secure-drv-outputs.nix * On FreeBSD, ‘touch’ is not in the test $PATH, so don't use it. 2011-08-08 14:08:38 +00:00
secure-drv-outputs.sh Don't put results symlinks in the tests directory 2012-09-11 19:14:15 -04:00
simple.builder.sh
simple.nix
simple.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
substituter.sh Don't keep "disabled" substituters running 2013-06-20 11:55:15 +02:00
substituter2.sh Don't keep "disabled" substituters running 2013-06-20 11:55:15 +02:00
substitutes.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
substitutes2.sh * Refactoring: remove unnecessary variables from the tests. 2011-10-10 21:32:34 +00:00
timeout.builder.sh Adda test for build-max-log-size 2013-09-02 12:44:30 +02:00
timeout.nix Show that --timeout doesn't work if the build produces log output 2013-04-23 17:16:29 +02:00
timeout.sh Adda test for build-max-log-size 2013-09-02 12:44:30 +02:00
user-envs.builder.sh Test priorities 2012-12-04 14:47:50 +01:00
user-envs.nix Test priorities 2012-12-04 14:47:50 +01:00
user-envs.sh Test nix-env --switch-generation 2014-02-26 18:45:26 +01:00