#!/usr/bin/vipsi



// ---- test dispatcher ----
if count globals == 0

	put " running test script \"test0.vs\" ",nl
	var script = "/home/pub/Develop/projects/vipsi/examples/test0.vs"
	var a = {0,1,2,7,8,9,10,11,12,17,18,19,20,21,22,27,28,29,66,99}

	put "call:",nl
	var i = 0
	do
		while ++i<=count a
		try
			var r = call(script,a[i])
			put " = ",r,nl
		else
			put " = ",r,nl
			put " errorstr = " log errorstr put nl
		then
	loop

	try
			put "failing call: "
			var r = call("/x/y/z/does not exist")
			log "didn't fail!" put nl
	else
			put " = ",r,nl
			put " errorstr = " log errorstr put nl
	then

	put "sys:",nl
	var i = 0
	do
		while ++i<=count a
		put "test ",a[i],": "
		try
			var r = sys(script,a[i])
			put " = ",r,nl
		else
			put " = ",r,nl
			put "errorstr = " log errorstr put nl
		then
	loop

	try
			put "failing call: "
			var r = sys("/x/y/z/does not exist")
			log "didn't fail!" put nl
	else
			put " = ",r,nl
			put " errorstr = " log errorstr put nl
	then

	put "all tests done!",nl


// ---- misc. tests ----
else

	put ">"
	var arg = string globals[1]
	put "> "


	if	 arg=="0"	put"[end 0]" 		end 0
	elif arg=="1"	put"[end 1]" 		end 1
	elif arg=="2"	put"[end 2]" 		end 2
	elif arg=="7"	put"[end \"a\"]"	end "a"
	elif arg=="8"	put"[end {1,2}]"	end {1,2}
	elif arg=="9"	put"[end]"   		end

	elif arg=="20"	proc e(){ put"{end 0}" 		end 0		} e() log "*didn't quit!*" end 0
	elif arg=="21"	proc e(){ put"{end 1}" 		end 1		} e() log "*didn't quit!*" end 0
	elif arg=="22"	proc e(){ put"{end 2}" 		end 2		} e() log "*didn't quit!*" end 0
	elif arg=="27"	proc e(){ put"{end \"a\"}"	end "a"		} e() log "*didn't quit!*" end 0
	elif arg=="28"	proc e(){ put"{end {1,2}}"	end {1,2}	} e() log "*didn't quit!*" end 0
	elif arg=="29"	proc e(){ put"{end}"   		end			} e() log "*didn't quit!*" end 0

	elif arg=="10"	put"[return 0]"		return 0
	elif arg=="11"	put"[return 1]"		return 1
	elif arg=="12"	put"[return 2]"		return 2
	elif arg=="17"	put"[return \"a\"]"	return "a"
	elif arg=="18"	put"[return {1,2}]"	return {1,2}
	elif arg=="19"	put"[return]"  		return

	elif arg=="99"	put"[eof]"  		/* resume and run into eof */
	elif arg=="66"	put"[error]" bollux	/* abort with error "variable not found" */
	else log "********* called with undefined test id <",arg,"> ***************" end 66
	then

then






