1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright (c) 2016 by Delphix. All rights reserved.
15#
16
17. $STF_SUITE/tests/functional/channel_program/channel_common.kshlib
18
19#
20# DESCRIPTION:
21#	Try returning various values that lua allows you to construct,
22#       but that cannot be represented as nvlists and therefore should
23#       cause the script to fail (but not panic). Try sending the values
24#       back to userland from both "return" and "error()".
25#
26
27verify_runnable "both"
28
29set -A args 'function() return 1 end' \
30	'{[{}]=true}' \
31	'{[function() return 1 end]=0}' \
32	'assert' \
33	'0, assert' \
34	'true, {[{}]=0}' \
35	'{val=true}, {val=false}' \
36	'{1, 2, 3}, {[4]=5}' \
37	'nil, true, 1, "test", {}, {val=true}' \
38	'{[false]=true, ["false"]=false}' \
39	'{[true]=false, ["true"]=true}' \
40	'{[0]=true, ["0"]=false}' \
41	'{0,0,0,["1"]=0}' \
42	'{0,0,0,["2"]=0}' \
43	'{0,0,0,["3"]=0}'
44
45typeset -i last_index=$((${#args[*]} - 1))
46for i in $(seq 0 $last_index); do
47	log_note "running program: ${args[i]}"
48	log_mustnot_checkerror_program "execution failed" $TESTPOOL - <<<"return ${args[i]}"
49	((i = i + 1))
50done
51
52for i in $(seq 0 $last_index); do
53	log_note "running program: ${args[i]}"
54	log_mustnot_checkerror_program "execution failed" $TESTPOOL - <<<"error(${args[i]})"
55	((i = i + 1))
56done
57
58log_pass "Returning lua constructs that cannot be converted to " \
59    "nvlists fails as expected."
60