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.
This commit is contained in:
Grissiom 2010-10-03 11:46:26 +08:00
parent 8910226d2f
commit 27df727ca1
6 changed files with 55 additions and 7 deletions

4
.gitignore vendored
View File

@ -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

8
fish.c
View File

@ -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 );

View File

@ -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

6
tests/top.err Normal file
View File

@ -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
^

6
tests/top.out Normal file
View File

@ -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

1
tests/top.status Normal file
View File

@ -0,0 +1 @@
0