aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-04-06 13:04:44 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-04-06 13:04:44 -0700
commit02f18cae0aa9c44beade38b1b14c9f59d54b9078 (patch)
tree6ac79b892acc6a1a19c9a6aa2926ad7ccb1a9272
parent4ff8e6e7818747d805ac44be0a36aedef4deaa5c (diff)
fix setting of $argv for `source` w/no args
Fixes #139
-rw-r--r--src/builtin.cpp2
-rw-r--r--tests/test1.in8
-rw-r--r--tests/test1.out4
3 files changed, 12 insertions, 2 deletions
diff --git a/src/builtin.cpp b/src/builtin.cpp
index dd67817a..86213a76 100644
--- a/src/builtin.cpp
+++ b/src/builtin.cpp
@@ -3375,7 +3375,7 @@ static int builtin_source(parser_t &parser, io_streams_t &streams, wchar_t **arg
parser.push_block(new source_block_t(fn_intern));
reader_push_current_filename(fn_intern);
- env_set_argv((argc>2)?(argv+2):(argv+1));
+ env_set_argv(argc > 1 ? argv + 2 : argv + 1);
res = reader_read(fd, streams.io_chain ? *streams.io_chain : io_chain_t());
diff --git a/tests/test1.in b/tests/test1.in
index d52d558e..ff6075cc 100644
--- a/tests/test1.in
+++ b/tests/test1.in
@@ -166,5 +166,11 @@ function always_fails
end
end
-always_fails ; echo $status
+# Verify $argv set correctly in sourced scripts.
+# Issue #139
+echo 'echo "source argv {$argv}"' | source
+echo 'echo "source argv {$argv}"' | source -
+echo 'echo "source argv {$argv}"' | source - abc
+echo 'echo "source argv {$argv}"' | source - abc def
+always_fails ; echo $status
diff --git a/tests/test1.out b/tests/test1.out
index fb5ea8c8..26251a3b 100644
--- a/tests/test1.out
+++ b/tests/test1.out
@@ -52,4 +52,8 @@ pipe 11
pipe 12
Checking for infinite loops in no-execute
before comment after comment
+source argv {}
+source argv {}
+source argv {abc}
+source argv {abc def}
1