mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-25 07:16:17 +02:00
Fix and extend nix-shell baseDir test
This commit is contained in:
parent
d5854f33e2
commit
f5b59fbc64
6 changed files with 20 additions and 2 deletions
|
@ -202,7 +202,7 @@ Bindings * MixEvalArgs::getAutoArgs(EvalState & state)
|
||||||
auto v = state.allocValue();
|
auto v = state.allocValue();
|
||||||
std::visit(overloaded {
|
std::visit(overloaded {
|
||||||
[&](const AutoArgExpr & arg) {
|
[&](const AutoArgExpr & arg) {
|
||||||
state.mkThunk_(*v, state.parseExprFromString(arg.expr, state.rootPath(".")));
|
state.mkThunk_(*v, state.parseExprFromString(arg.expr, true ? state.rootPath(absPath(getCommandBaseDir())) : state.rootPath(".")));
|
||||||
},
|
},
|
||||||
[&](const AutoArgString & arg) {
|
[&](const AutoArgString & arg) {
|
||||||
v->mkString(arg.s);
|
v->mkString(arg.s);
|
||||||
|
|
|
@ -29,6 +29,7 @@ struct Completions final : AddCompletions
|
||||||
*/
|
*/
|
||||||
class RootArgs : virtual public Args
|
class RootArgs : virtual public Args
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
/**
|
/**
|
||||||
* @brief The command's "working directory", but only set when top level.
|
* @brief The command's "working directory", but only set when top level.
|
||||||
*
|
*
|
||||||
|
|
|
@ -183,6 +183,9 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
struct MyArgs : LegacyArgs, MixEvalArgs
|
struct MyArgs : LegacyArgs, MixEvalArgs
|
||||||
{
|
{
|
||||||
using LegacyArgs::LegacyArgs;
|
using LegacyArgs::LegacyArgs;
|
||||||
|
void setBaseDir(Path baseDir) {
|
||||||
|
commandBaseDir = baseDir;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MyArgs myArgs(myName, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
MyArgs myArgs(myName, [&](Strings::iterator & arg, const Strings::iterator & end) {
|
||||||
|
@ -290,6 +293,9 @@ static void main_nix_build(int argc, char * * argv)
|
||||||
state->repair = myArgs.repair;
|
state->repair = myArgs.repair;
|
||||||
if (myArgs.repair) buildMode = bmRepair;
|
if (myArgs.repair) buildMode = bmRepair;
|
||||||
|
|
||||||
|
if (inShebang) {
|
||||||
|
myArgs.setBaseDir(absPath(dirOf(script)));
|
||||||
|
}
|
||||||
auto autoArgs = myArgs.getAutoArgs(*state);
|
auto autoArgs = myArgs.getAutoArgs(*state);
|
||||||
|
|
||||||
auto autoArgsWithInNixShell = autoArgs;
|
auto autoArgsWithInNixShell = autoArgs;
|
||||||
|
|
|
@ -72,8 +72,9 @@ chmod a+rx $TEST_ROOT/shell.shebang.expr
|
||||||
! $TEST_ROOT/shell.shebang.expr bar
|
! $TEST_ROOT/shell.shebang.expr bar
|
||||||
cp shell.nix config.nix $TEST_ROOT
|
cp shell.nix config.nix $TEST_ROOT
|
||||||
# Should succeed
|
# Should succeed
|
||||||
|
echo "cwd: $PWD"
|
||||||
output=$($TEST_ROOT/shell.shebang.expr bar)
|
output=$($TEST_ROOT/shell.shebang.expr bar)
|
||||||
[ "$output" = '-e load(ARGV.shift) -- '"$TEST_ROOT"'/shell.shebang.expr bar' ]
|
[ "$output" = foo ]
|
||||||
|
|
||||||
# Test nix-shell shebang mode again with metacharacters in the filename.
|
# Test nix-shell shebang mode again with metacharacters in the filename.
|
||||||
# First word of filename is chosen to not match any file in the test root.
|
# First word of filename is chosen to not match any file in the test root.
|
||||||
|
|
|
@ -43,6 +43,7 @@ let pkgs = rec {
|
||||||
ASCII_PERCENT = "%";
|
ASCII_PERCENT = "%";
|
||||||
ASCII_AT = "@";
|
ASCII_AT = "@";
|
||||||
TEST_inNixShell = if inNixShell then "true" else "false";
|
TEST_inNixShell = if inNixShell then "true" else "false";
|
||||||
|
FOO = fooContents;
|
||||||
inherit stdenv;
|
inherit stdenv;
|
||||||
outputs = ["dev" "out"];
|
outputs = ["dev" "out"];
|
||||||
} // {
|
} // {
|
||||||
|
|
9
tests/functional/shell.shebang.expr
Executable file
9
tests/functional/shell.shebang.expr
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#! @ENV_PROG@ nix-shell
|
||||||
|
#! nix-shell "{ script, path, ... }: assert path == ./shell.nix; script { }"
|
||||||
|
#! nix-shell --no-substitute
|
||||||
|
#! nix-shell --expr
|
||||||
|
#! nix-shell --arg script "import ./shell.nix"
|
||||||
|
#! nix-shell --arg path "./shell.nix"
|
||||||
|
#! nix-shell -A shellDrv
|
||||||
|
#! nix-shell -i bash
|
||||||
|
echo "$FOO"
|
Loading…
Reference in a new issue