diff --git a/src/builtin_functions.cpp b/src/builtin_functions.cpp index 8b5b16d97..42575b503 100644 --- a/src/builtin_functions.cpp +++ b/src/builtin_functions.cpp @@ -337,6 +337,11 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) { return STATUS_CMD_OK; } + // If we query with no argument, just return false. + if (opts.query && argc == optind) { + return STATUS_CMD_ERROR; + } + if (opts.list || argc == optind) { wcstring_list_t names = function_get_names(opts.show_hidden); std::sort(names.begin(), names.end()); diff --git a/tests/function.err b/tests/function.err index 2d69cbb05..7257df763 100644 --- a/tests/function.err +++ b/tests/function.err @@ -29,3 +29,6 @@ fish: function: The name 'test' is reserved, and can not be used as a function name function test; echo banana; end ^ + +#################### +# Checking `functions -q` without arguments diff --git a/tests/function.in b/tests/function.in index ef9bd537d..a65183076 100644 --- a/tests/function.in +++ b/tests/function.in @@ -58,4 +58,7 @@ test "$name3[2..-1]" = "$name3a[2..-1]"; and echo "3 = 3a" logmsg Checking reserved names function test; echo banana; end + +logmsg Checking `functions -q` without arguments +functions -q; or echo "False" exit 0 diff --git a/tests/function.out b/tests/function.out index 0e44e0182..aec07aabf 100644 --- a/tests/function.out +++ b/tests/function.out @@ -71,3 +71,7 @@ function name3a --argument arg1 arg2 #################### # Checking reserved names + +#################### +# Checking `functions -q` without arguments +False