aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Grissiom <chaos.proton@gmail.com>2010-10-03 11:46:26 +0800
committerGravatar Grissiom <chaos.proton@gmail.com>2010-10-03 11:46:26 +0800
commit27df727ca11dfeac74214609771eacfccd4d5c08 (patch)
tree20147ec14a1c4abe7e2548597e69b3a8848f3050
parent8910226d2f63db6fc7256b388187a249c9384478 (diff)
don't parse the options that should be passed to fish scripts
This commit makes fish_parse_opt stop at first non-option argument, which expected as fish script name and pass the remaining argument to that script. I also updated the test cases.
-rw-r--r--.gitignore4
-rw-r--r--fish.c8
-rwxr-xr-xtests/test.fish37
-rw-r--r--tests/top.err6
-rw-r--r--tests/top.out6
-rw-r--r--tests/top.status1
6 files changed, 55 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 43bbc2cc..db577630 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,7 +29,5 @@ share/man/
toc.txt
user_doc/
xsel-0.9.6/
-tests/tmp.out
-tests/tmp.err
-tests/tmp.status
+tests/*tmp.*
tests/foo.txt
diff --git a/fish.c b/fish.c
index 459eb27a..062c9a72 100644
--- a/fish.c
+++ b/fish.c
@@ -66,7 +66,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
/**
The string describing the single-character options accepted by the main fish binary
*/
-#define GETOPT_STRING "hilnvc:p:d:"
+#define GETOPT_STRING "+hilnvc:p:d:"
/**
Parse init files
@@ -328,7 +328,7 @@ int main( int argc, char **argv )
else
{
char **ptr;
- char *file = *(argv+1);
+ char *file = *(argv+(my_optind++));
int i;
string_buffer_t sb;
int fd;
@@ -340,11 +340,11 @@ int main( int argc, char **argv )
return 1;
}
- if( *(argv+2))
+ if( *(argv+my_optind))
{
sb_init( &sb );
- for( i=1,ptr = argv+2; *ptr; i++, ptr++ )
+ for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
{
if( i != 1 )
sb_append( &sb, ARRAY_SEP_STR );
diff --git a/tests/test.fish b/tests/test.fish
index 74e562b9..610c966e 100755
--- a/tests/test.fish
+++ b/tests/test.fish
@@ -4,6 +4,43 @@
# instad of using autotest to provide additional
# testing for fish. :-)
+
+if [ "$argv" != '-n' ]
+ # begin...end has bug in error redirecting...
+ begin
+ ../fish -n ./test.fish ^top.tmp.err
+ ../fish -n ./test.fish -n ^^top.tmp.err
+ ../fish ./test.fish -n ^^top.tmp.err
+ end | tee top.tmp.out
+ echo $status >top.tmp.status
+ set res ok
+ if diff top.tmp.out top.out >/dev/null
+ else
+ set res fail
+ echo Output differs for file test.fish
+ end
+
+ if diff top.tmp.err top.err >/dev/null
+ else
+ set res fail
+ echo Error output differs for file test.fish
+ end
+
+ if test (cat top.tmp.status) = (cat top.status)
+ else
+ set res fail
+ echo Exit status differs for file test.fish
+ end
+
+ if test $res = ok;
+ echo File test.fish tested ok
+ else
+ echo File test.fish failed tests
+ end;
+
+ exit
+end
+
echo Testing high level script functionality
for i in *.in
diff --git a/tests/top.err b/tests/top.err
new file mode 100644
index 00000000..73a623c4
--- /dev/null
+++ b/tests/top.err
@@ -0,0 +1,6 @@
+fish: Expected redirection specification, got token of type '$i'
+/usr/local/src/grissioms-fish-shell/tests/test.fish (line 51): ../fish <$i >tmp.out ^tmp.err
+ ^
+fish: Expected redirection specification, got token of type '$i'
+/usr/local/src/grissioms-fish-shell/tests/test.fish (line 51): ../fish <$i >tmp.out ^tmp.err
+ ^
diff --git a/tests/top.out b/tests/top.out
new file mode 100644
index 00000000..c3a60ba6
--- /dev/null
+++ b/tests/top.out
@@ -0,0 +1,6 @@
+Testing high level script functionality
+File test1.in tested ok
+File test2.in tested ok
+File test3.in tested ok
+File test4.in tested ok
+File test5.in tested ok
diff --git a/tests/top.status b/tests/top.status
new file mode 100644
index 00000000..573541ac
--- /dev/null
+++ b/tests/top.status
@@ -0,0 +1 @@
+0