#!/usr/bin/perl
# Test super methods of various language bindings.
# For this purpose we have super_test_n objects that have methods for each
# language, named language_meth, that call super, with different contortions
# needed to get to the super methods. The object's expected fields list the
# values the methods in that object are expected to return (plus any
# additonal parameters passed to the methods should be returned by the
# final super method, to make sure they get there ok).
use Mooix::Thing;
use Test::More import => ['!fail'];
run sub {
	my $this=shift;
	my @langs=$this->languages;
	my @test_objects=$this->list;

	plan tests => int(@langs) * int(@test_objects),
	     import => ['!fail'];
	
	foreach my $obj (@test_objects) {
		next unless $obj->id =~ /super_test_\d+/;
		foreach my $lang (@langs) {
			my $meth=$lang."_meth";
			SKIP: {
				skip "unimplmented test method", 1
					unless $obj->implements($meth);
				
				my @ret=$obj->$meth(testing => $obj);
				if (eq_array(\@ret, [$obj->expected, 'testing', $obj])) {
					# object name is strigified to
					# work around Test::Builder bug
					# in perl 5.8.1.
					ok(1, "$obj");
				}
				else {
					ok(0, "$obj");
					diag("failed for language: $lang obj: $obj\n");
					diag("got ret: ".join(", ", @ret));
					diag("vs:      ".join(", ", $obj->expected, 'testing', $obj));
				}
			}
		}
	}
}
