# SPDX-License-Identifier: GPL-2.0-or-later

namespace import testing_helpers::*
namespace import configure_testing::*

adapter driver dummy
jtag newtap tap cpu -irlen 5

check_syntax_err {target create}
check_syntax_err {target create}
check_syntax_err {target create test.target}
check_error_matches -chain-position {target create test.target testee}

{*}[target_create_first_args] {*}[simple_configure_options]

foreach {opt arg} [simple_configure_options] {
	check_error_matches ".*${opt}.*" {{*}[target_create_first_args] $opt}
}

foreach {opt1 arg1} [simple_configure_options] {
	foreach {opt2 arg2} [simple_configure_options] {
		check_error_matches ".*${opt2}.*" \
			{{*}[target_create_first_args] $opt1 $arg1 $opt2}
		check_error_matches {} \
			{{*}[target_create_first_args] $opt1 $opt2 $arg2}
	}
}

check_error_matches ".*-type.*" \
	{{*}[target_create_first_args] -type}

check_error_matches ".*-type.*" \
	{{*}[target_create_first_args] {*}[simple_configure_options] -type}

check_error_matches {.*-event [^ ]+ .*} \
	{{*}[target_create_first_args] -event}

check_error_matches {.*not-an-event.*} \
	{{*}[target_create_first_args] -event not-an-event}

check_error_matches {.*-event examine-start [^ ]+.*} \
	{{*}[target_create_first_args] -event examine-start}

{*}[target_create_first_args] {*}[simple_configure_options] \
	-event examine-start body
{*}[target_create_first_args] {*}[simple_configure_options] \
	-event examine-start body \
	-event examine-end another-body \
	-event examine-start new-body
{*}[target_create_first_args] -event examine-start body {*}[simple_configure_options]

{*}[target_create_first_args] {*}[simple_configure_options] -defer-examine

shutdown
