Basically working. Checking against actual use cases.

This commit is contained in:
Judson 2017-05-03 20:27:42 -07:00
parent 2b414e1c15
commit 66fed6d28f
No known key found for this signature in database
GPG Key ID: 1817B08954BF0B7D
6 changed files with 43 additions and 16 deletions

View File

@ -82,15 +82,15 @@ let
paths = envPaths; paths = envPaths;
pathsToLink = [ "/lib" ]; pathsToLink = [ "/lib" ];
postBuild = genStubsScript defs // args // { postBuild = genStubsScript (defs // args // {
inherit confFiles bundler; inherit confFiles bundler groups;
binPaths = envPaths; binPaths = envPaths;
} + lib.optionalString (postBuild != null) postBuild; }) + lib.optionalString (postBuild != null) postBuild;
meta = { platforms = ruby.meta.platforms; } // meta; meta = { platforms = ruby.meta.platforms; } // meta;
passthru = rec { passthru = rec {
inherit ruby bundler gems; # drvName; inherit ruby bundler gems mainGem confFiles; # drvName;
wrappedRuby = stdenv.mkDerivation { wrappedRuby = stdenv.mkDerivation {
name = "wrapped-ruby-${pname}"; name = "wrapped-ruby-${pname}";

View File

@ -24,7 +24,7 @@
}@args: }@args:
let let
inherit (import ./functions.nix (defs // args)) genStubsScript; inherit (import ./functions.nix {inherit lib ruby gemConfig groups; }) genStubsScript;
drvName = drvName =
if name != null then name if name != null then name
@ -62,21 +62,21 @@ let
# The basicEnv should be put into passthru so that e.g. nix-shell can use it. # The basicEnv should be put into passthru so that e.g. nix-shell can use it.
in in
if builtins.trace "pname: ${toString pname}" pname == null then if pname == null then
basicEnv // { inherit name; } basicEnv // { inherit name; }
else else
(buildEnv { (buildEnv {
inherit ignoreCollisions; inherit ignoreCollisions;
name = builtins.trace "name: ${toString drvName}" drvName; name = drvName;
paths = envPaths; paths = envPaths;
pathsToLink = [ "/lib" ]; pathsToLink = [ "/lib" ];
postBuild = genStubsScript defs // args // { postBuild = genStubsScript {
inherit bundler; inherit lib ruby bundler groups;
confFiles = basicEnv.confFiles; confFiles = basicEnv.confFiles;
binPaths = [ basicEnv.mainGem ]; binPaths = [ basicEnv.gems."${pname}" ];
} + lib.optionalString (postBuild != null) postBuild; } + lib.optionalString (postBuild != null) postBuild;
meta = { platforms = ruby.meta.platforms; } // meta; meta = { platforms = ruby.meta.platforms; } // meta;

View File

@ -20,7 +20,7 @@ rec {
then attrs // gemConfig."${attrs.gemName}" attrs then attrs // gemConfig."${attrs.gemName}" attrs
else attrs); else attrs);
genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths }: '' genStubsScript = { lib, ruby, confFiles, bundler, groups, binPaths, ... }: ''
${ruby}/bin/ruby ${./gen-bin-stubs.rb} \ ${ruby}/bin/ruby ${./gen-bin-stubs.rb} \
"${ruby}/bin/ruby" \ "${ruby}/bin/ruby" \
"${confFiles}/Gemfile" \ "${confFiles}/Gemfile" \

View File

@ -1,9 +1,17 @@
/*
Run with:
nix-build -E 'with import <nixpkgs> { }; callPackage ./test.nix {}' --show-trace; and cat result
Confusingly, the ideal result ends with something like:
error: build of /nix/store/3245f3dcl2wxjs4rci7n069zjlz8qg85-test-results.tap.drv failed
*/
{ writeText, lib, ruby, defaultGemConfig, callPackage }: { writeText, lib, ruby, defaultGemConfig, callPackage }:
let let
test = import ./testing.nix; test = import ./testing.nix;
tap = import ./tap-support.nix; tap = import ./tap-support.nix;
bundlerEnv = callPackage ./default.nix {}; bundlerEnv = callPackage ./default.nix {};
basicEnv = callPackage ./basic.nix {};
testConfigs = { testConfigs = {
groups = ["default"]; groups = ["default"];
@ -22,6 +30,18 @@ let
if builtins.isAttrs actual then if builtins.isAttrs actual then
(test.passed "is a set") else (test.passed "is a set") else
(test.failed "is not a set, was ${builtins.typeOf actual}: ${toString actual}"); (test.failed "is not a set, was ${builtins.typeOf actual}: ${toString actual}");
haveKeys = expected: actual:
if builtins.all
(ex: builtins.any (ac: ex == ac) (builtins.attrNames actual))
expected then
(test.passed "has expected keys") else
(test.failed "keys differ: expected [${lib.concatStringsSep ";" expected}] have [${lib.concatStringsSep ";" (builtins.attrNames actual)}]");
havePrefix = expected: actual:
if lib.hasPrefix expected actual then
(test.passed "has prefix '${expected}'") else
(test.failed "prefix '${expected}' not found in '${actual}'");
}; };
justName = bundlerEnv { justName = bundlerEnv {
@ -29,9 +49,12 @@ let
gemset = ./test/gemset.nix; gemset = ./test/gemset.nix;
}; };
pnamed = bundlerEnv { pnamed = basicEnv {
pname = "test"; pname = "test";
gemdir = ./test;
gemset = ./test/gemset.nix; gemset = ./test/gemset.nix;
gemfile = ./test/Gemfile;
lockfile = ./test/Gemfile.lock;
}; };
results = builtins.concatLists [ results = builtins.concatLists [
@ -40,10 +63,14 @@ let
name = should.equal "test"; name = should.equal "test";
}) })
(test.run "bundlerEnv { pname }" pnamed (test.run "bundlerEnv { pname }" pnamed
[
(should.haveKeys [ "name" "env" "postBuild" ])
{ {
name = should.equal "test-0.1.2"; name = should.equal "test-0.1.2";
env = should.beASet; env = should.beASet;
}) postBuild = should.havePrefix "nananana";
}
])
]; ];
in in
writeText "test-results.tap" (tap.output results) writeText "test-results.tap" (tap.output results)