
# mock the commands the ruby group uses
set prefix                    /opt/local
set os.platform               mac

proc name p0                  {
	global name.found
	set name.found $p0
}
proc version p0               {
	global version.found
	set version.found $p0
}
proc categories p0            {}
proc distname p0              {}
proc dist_subdir p0           {}
proc depends_lib p0           {
	global depends_lib.found
	set depends_lib.found $p0
}
proc post-extract p0          {}
proc configure.cmd {p0 p1 p2} {}
proc configure.pre_args p0    {}
proc build.target p0          {
	global build.target.found
	set build.target.found $p0
}
proc build.cmd {p0 p1 p2}     {}
proc pre-destroot p0          {}
proc destroot.cmd {p0 p1 p2}  {}
proc destroot.target p0       {}
proc destroot.destdir {}      {}
proc post-destroot p0         {}

# evaluate ruby group file
set dir [file dirname ${argv0}]
source "${dir}/../ruby-1.0.tcl"

namespace eval tests {
	# Backwards compatible behaviour, assumes ruby 1.8
	proc test_rubysetup_compatible {} {
		global ruby.version
		global ruby.module
		global ruby.project
		global ruby.filename 
		global ruby.bin
		global ruby.docs
		global build.target.found
		global name.found
		global version.found
		global depends_lib.found

		ruby.setup {test_module tmod} 9.9 setup.rb {README INSTALL}

		if {![string equal "1.8" ${ruby.version}]} { error "ruby.version failed'" }
		if {![string equal "test_module" ${ruby.module}]} { error "ruby.module failed" }
		if {![string equal "tmod" ${ruby.project}]} { error "ruby.project failed" }
		if {![string equal "tmod" ${ruby.filename}]} { error "ruby.filename failed" }
		if {![string equal {README INSTALL} ${ruby.docs}]} { error "ruby.docs failed"}
		if {![string equal "setup" ${build.target.found}]} { error "type-derived field build.target failed: ${build.target.found}"}
		if {![string equal "rb-test_module" ${name.found}]} { error "drived name failed: ${name.found}" }
		if {![string equal "9.9" ${version.found}]} { error "port version set failed" }
		if {![string equal port:ruby ${depends_lib.found}]} { error "depends_lib failed: ${depends_lib.found}" }
	}

	proc test_rubysetup_ruby19 {} {
		global ruby.version
		global ruby.module
		global ruby.project
		global ruby.filename 
		global ruby.bin
		global ruby.docs

		global build.target.found
		global name.found
		global version.found
		global depends_lib.found

		ruby.setup {test_module tmod} 9.9 setup.rb {README INSTALL} custom ruby19

		# changed prefix
		if {![string equal "1.9.0" ${ruby.version}]} { error "ruby.version failed: '${ruby.version}'" }
		if {![string equal "rb19-test_module" ${name.found}]} { error "drived name failed: ${name.found}" }

		if {![string equal "test_module" ${ruby.module}]} { error "ruby.module failed" }
		if {![string equal "tmod" ${ruby.project}]} { error "ruby.project failed" }
		if {![string equal "tmod" ${ruby.filename}]} { error "ruby.filename failed" }
		if {![string equal {README INSTALL} ${ruby.docs}]} { error "ruby.docs failed"}
		if {![string equal "setup" ${build.target.found}]} { error "type-derived field failed: ${build.target.found}"}
		if {![string equal "9.9" ${version.found}]} { error "port version set failed" }
		if {![string equal "port:ruby19" ${depends_lib.found}]} { error "depends_lib failed: ${depends_lib.found}" }
	}

	proc test_setup_implementation_specifics {} {
		if {![catch {ruby.setup_implementation_specifics unknown_impl}]} {
			error "wrong implementation name should raise error"
		}
	}
	
	# run all tests
	foreach proc [info procs test_*] { 
	        $proc
	}
}

