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;
pathsToLink = [ "/lib" ];
postBuild = genStubsScript defs // args // {
inherit confFiles bundler;
postBuild = genStubsScript (defs // args // {
inherit confFiles bundler groups;
binPaths = envPaths;
} + lib.optionalString (postBuild != null) postBuild;
}) + lib.optionalString (postBuild != null) postBuild;
meta = { platforms = ruby.meta.platforms; } // meta;
passthru = rec {
inherit ruby bundler gems; # drvName;
inherit ruby bundler gems mainGem confFiles; # drvName;
wrappedRuby = stdenv.mkDerivation {
name = "wrapped-ruby-${pname}";

View file

@ -24,7 +24,7 @@
}@args:
let
inherit (import ./functions.nix (defs // args)) genStubsScript;
inherit (import ./functions.nix {inherit lib ruby gemConfig groups; }) genStubsScript;
drvName =
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.
in
if builtins.trace "pname: ${toString pname}" pname == null then
if pname == null then
basicEnv // { inherit name; }
else
(buildEnv {
inherit ignoreCollisions;
name = builtins.trace "name: ${toString drvName}" drvName;
name = drvName;
paths = envPaths;
pathsToLink = [ "/lib" ];
postBuild = genStubsScript defs // args // {
inherit bundler;
postBuild = genStubsScript {
inherit lib ruby bundler groups;
confFiles = basicEnv.confFiles;
binPaths = [ basicEnv.mainGem ];
binPaths = [ basicEnv.gems."${pname}" ];
} + lib.optionalString (postBuild != null) postBuild;
meta = { platforms = ruby.meta.platforms; } // meta;

View file

@ -20,7 +20,7 @@ rec {
then attrs // gemConfig."${attrs.gemName}" 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" \
"${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 }:
let
test = import ./testing.nix;
tap = import ./tap-support.nix;
bundlerEnv = callPackage ./default.nix {};
basicEnv = callPackage ./basic.nix {};
testConfigs = {
groups = ["default"];
@ -22,6 +30,18 @@ let
if builtins.isAttrs actual then
(test.passed "is a set") else
(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 {
@ -29,9 +49,12 @@ let
gemset = ./test/gemset.nix;
};
pnamed = bundlerEnv {
pnamed = basicEnv {
pname = "test";
gemdir = ./test;
gemset = ./test/gemset.nix;
gemfile = ./test/Gemfile;
lockfile = ./test/Gemfile.lock;
};
results = builtins.concatLists [
@ -40,10 +63,14 @@ let
name = should.equal "test";
})
(test.run "bundlerEnv { pname }" pnamed
{
name = should.equal "test-0.1.2";
env = should.beASet;
})
[
(should.haveKeys [ "name" "env" "postBuild" ])
{
name = should.equal "test-0.1.2";
env = should.beASet;
postBuild = should.havePrefix "nananana";
}
])
];
in
writeText "test-results.tap" (tap.output results)