From 7cfe028b9d52785e4cbb0f13c626eb6e959f5f44 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Mon, 28 Nov 2016 18:04:37 -0800 Subject: [PATCH] fix `functions --copy` Fixes #3601 --- src/builtin.cpp | 2 +- tests/function.in | 18 ++++++++++++++++-- tests/function.out | 9 +++++++++ 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/builtin.cpp b/src/builtin.cpp index 3f1dccbf0..2b3de5d64 100644 --- a/src/builtin.cpp +++ b/src/builtin.cpp @@ -1194,7 +1194,7 @@ static int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t ** return STATUS_BUILTIN_ERROR; } - if ((wcsfuncname(new_func) != 0) || parser_keywords_is_reserved(new_func)) { + if (!wcsfuncname(new_func) || parser_keywords_is_reserved(new_func)) { streams.err.append_format(_(L"%ls: Illegal function name '%ls'\n"), argv[0], new_func.c_str()); builtin_print_help(parser, streams, argv[0], streams.err); diff --git a/tests/function.in b/tests/function.in index b3e8d6ac3..ad4b67de0 100644 --- a/tests/function.in +++ b/tests/function.in @@ -35,12 +35,26 @@ frob # `name4` were created. See issue #2068. That behavior is not what we want. # The function name must always be the first argument of the `function` # command. See issue #2827. -function name1 -a arg1 arg2 ; end +function name1 -a arg1 arg2 ; echo hello; end function -a arg1 arg2 name2 ; end -function name3 --argument-names arg1 arg2 ; end +function name3 --argument-names arg1 arg2 ; echo hello; echo goodbye; end function --argument-names arg1 arg2 name4 ; end function name5 abc --argument-names def ; end functions -q name1; and echo "Function name1 found" functions -q name2; or echo "Function name2 not found as expected" functions -q name3; and echo "Function name3 found" functions -q name4; or echo "Function name4 not found as expected" + +# Verify that functions can be copied. Tests against regression of issue #3601. +functions -c name1 name1a +functions --copy name3 name3a +functions -q name1a +or echo "Function name1a not found as expected" +functions -q name3a +or echo "Function name3a not found as expected" +echo Checking that the copied functions are identical other than the name +diff (functions name1 | psub) (functions name1a | psub) +diff (functions name3 | psub) (functions name3a | psub) +# The diff would cause us to exit with a non-zero status even if it produces +# the expected output. +exit 0 diff --git a/tests/function.out b/tests/function.out index 4c3e14b01..6845d37f0 100644 --- a/tests/function.out +++ b/tests/function.out @@ -22,3 +22,12 @@ Function name1 found Function name2 not found as expected Function name3 found Function name4 not found as expected +Checking that the copied functions are identical other than the name +1c1 +< function name1 --argument arg1 arg2 +--- +> function name1a --argument arg1 arg2 +1c1 +< function name3 --argument arg1 arg2 +--- +> function name3a --argument arg1 arg2