Skip to content

Suggestion: __print_example for help example testing #327

@balupton

Description

@balupton

Now that __print_Help is coming into fruition, we could do something like this:

	$(__print_example --stdout='https' --status=0 -- get-url-protocol -- 'htstps://bevry.me' || exit $?)
	function __print_example {
		local item eval=() command expected_stdout expected_status
		while [[ $# -ne 0 ]]; do
			item="$1"
			shift
			case "$item" in
			'--eval='*) eval_command="${item#*=}" ;;
			'--stdout='*) expected_stdout="${item#*=}" ;;
			'--status='*) expected_status="${item#*=}" ;;
			'--')
				eval+=("$@")
				shift $#
				;;
			'--'*) __unrecognised_flag "$item" || return $? ;;
			*) __unrecognised_argument "$item" || return $? ;;
			esac
		done
		# @todo cache the result, or figure out error, and perhaps don't test but just output what the results are
		eval-tester --stdout="$expected_stdout" --status="$expected_status" -- "${eval[@]}"  || return $?
		command="$(echo-escape-command -- "${eval[@]}")" || return $?
		cat <<-EOF || return $?
			\`\`\`
			$command
			\`\`\`
			Outputs: \`$expected_stdout\`
			Returns: [$expected_status]
		EOF
		return 0
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementImprovement or suggestion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions