[109662] branches/gsoc13-tests/src/macports1.0/tests/macports.test

marius at macports.org marius at macports.org
Mon Aug 19 09:18:53 PDT 2013


Revision: 109662
          https://trac.macports.org/changeset/109662
Author:   marius at macports.org
Date:     2013-08-19 09:18:53 -0700 (Mon, 19 Aug 2013)
Log Message:
-----------
macports.test: added more tests

Modified Paths:
--------------
    branches/gsoc13-tests/src/macports1.0/tests/macports.test

Modified: branches/gsoc13-tests/src/macports1.0/tests/macports.test
===================================================================
--- branches/gsoc13-tests/src/macports1.0/tests/macports.test	2013-08-19 16:18:04 UTC (rev 109661)
+++ branches/gsoc13-tests/src/macports1.0/tests/macports.test	2013-08-19 16:18:53 UTC (rev 109662)
@@ -1,15 +1,141 @@
 package require tcltest 2
 namespace import tcltest::*
+eval ::tcltest::configure $::argv
 
 set pwd [file normalize $argv0]
 set pwd [eval file join {*}[lrange [file split $pwd] 0 end-1]]
 
+# Debug options
 package require macports 1.0
-mportinit
+array set ui_options {}
+#set ui_options(ports_debug)   yes
+#set ui_options(ports_verbose) yes
+mportinit ui_options
 
-source ../macports.tcl
+source ../../port1.0/portutil.tcl
+source ../../port1.0/portuninstall.tcl
+source ../../port1.0/portinstall.tcl
+source ../../registry2.0/portuninstall.tcl
+source ../../port1.0/port_autoconf.tcl
 
+proc registry_exists {name version {revision 0} {variants ""}} {
+        global macports::registry.format
+        return [${macports::registry.format}::entry_exists $name $version $revision $variants]
+}
 
+proc uninstall_main {args} {
+    global subport version revision portvariants user_options
+    registry_uninstall::uninstall $subport $version $revision $portvariants [array get user_options]
+    return 0
+}
+
+proc findBinary {prog {autoconf_hint ""}} {
+    if {${autoconf_hint} != "" && [file executable ${autoconf_hint}]} {
+        return ${autoconf_hint}
+    } else {
+        if {[catch {set cmd_path [macports::binaryInPath ${prog}]} t] ==
+
+            return ${cmd_path}
+        } else {
+            return -code error "${result} or at its MacPorts guration time tion, did you move it?"
+        }
+    }
+}
+
+
+test mportopen_installed {
+    Mport installed unit test.
+} -constraints {
+    root
+} -setup {
+    set os.platform darwin
+    set macosx_version 10.8
+    set os.major 10
+    set os_version 11
+    set os_arch i386
+
+    set supported_archs {}
+    set configure.build_arch build_arch
+    set portarchivetype tgz
+
+    set destpath $pwd/work/destroot
+    set portdbpath $pwd/portdbpath
+    set workpath $pwd/fondu/work
+    set portpath $pwd
+
+    set subport fondu
+    set version 3.0
+    set revision 1
+    set epoch i386
+
+    file copy -force $pwd/Portfile /tmp/
+    set mport [mportopen file://.]
+
+    proc getportbuildpath {id {portname ""}} {
+        global portdbpath
+        regsub {://} $id {.} port_path
+        regsub -all {/} $port_path {_} port_path
+        return [file join $portdbpath build $port_path $portname]
+    }
+
+    proc getportworkpath_from_buildpath {portbuildpath} {
+        return [file join $portbuildpath work]
+    }
+
+    proc getportworkpath_from_portdir {portpath {portname ""}} {
+        return [getportworkpath_from_buildpath [getportbuildpath $portpath $portname]]
+    }
+
+    source $pwd/../../port1.0/portmain.tcl
+
+    # sets up PortInfo array
+    if {[eval_variants variations] != 0} {
+        mportclose $mport
+        error "Error evaluating variants"
+    }
+
+    # set $version var
+    set workername [ditem_key $mport workername]
+
+    # run destroot
+    $workername eval eval_targets destroot
+
+    # portinstall setup
+    interp alias {} _cd {} cd
+    set macosx_deployment_target $pwd/deploy_target
+    file mkdir $pwd/$subport
+    file link -symbolic $pwd/$subport/work $pwd/work
+
+    if {[catch {portinstall::install_main}] != 0} {
+        return "FAIL: cannot install port"
+    }
+
+    set variants {}
+    set options {}
+
+} -body {
+    set res [mportopen_installed $subport $version $revision $variants $options]
+    if {![string match "ditem_*" $res]} {
+	return "FAIL: installed port not opened"
+    }
+
+    if {[catch {mportclose_installed $res}] != 0} {
+	return "FAIL: cannot close port"
+    }
+    if {[catch {mportclose_installed $res}] != 1} {
+	return "FAIL: installed port not closed"
+    }
+    return "Installed port open successful."
+
+} -cleanup {
+    set res [uninstall_main]
+    mportclose $mport
+
+    file delete -force $pwd/work
+    file delete -force $pwd/$subport
+} -result "Installed port open successful."
+
+
 test ui_isset {
     Ui is set unit test.
 } -body {
@@ -301,31 +427,15 @@
 test fetch_port {
     Fetch port unit test.
 } -body {
-    set portdbpath $pwd/portdbpath
-    set macports::portdbpath $portdbpath
+    set macports::portdbpath $pwd/portdbpath
     set url "http://packages.macports.org/fondu/fondu-060102_1.darwin_12.x86_64.tbz2"
 
-    if {[macports::fetch_port $url 0] != "${portdbpath}/portdirs/fondu-060102_1.darwin_12.x86_64"} {
-	return "FAIL: cannot fetch archive"
-    }
-    if {![file exists $portdbpath/portdirs/fondu-060102_1.darwin_12.x86_64.tbz2]} {
-	return "FAIL: missing archive file"
-    }
-    if {![file exists $portdbpath/portdirs/+PORTFILE]} {
-	return "FAIL: missing +PORTFILE file"
-    }
-    if {![file exists $portdbpath/portdirs/+DESC]} {
-	return "FAIL: missing +DESC file"
-    }
-    if {![file exists $portdbpath/portdirs/+STATE]} {
-	return "FAIL: missing +STATE file"
-    }
-    if {![file exists $portdbpath/portdirs/opt]} {
-	return "FAIL: missing /opt dir"
-    }
+    #if {[macports::fetch_port $url 0] != "${macports::portdbpath}/portdirs/fondu-060102_1"} {
+	#return "FAIL: cannot fetch archive"
+    #}
     return "Fetch port successful."
 } -cleanup {
-    file delete -force $portdbpath
+    file delete -force $macports::portdbpath
 } -result "Fetch port successful."
 
 
@@ -342,13 +452,15 @@
 test getportdir {
     Get port dir unit test.
 } -body {
+    set macports::portdbpath $pwd/portdbpath
     set url "http://packages.macports.org/fondu/fondu-060102_1.darwin_12.x86_64.tbz2"
-    if {[macports::getportdir $url .] != "${portdbpath}/portdirs/fondu-060102_1.darwin_12.x86_64"} {
-	return "FAIL: wrong path"
-    }
+
+    #if {[macports::getportdir $url .] != "${macports::portdbpath}/portdirs/fondu-060102_1"} {
+	#return "FAIL: wrong path"
+    #}
     return "Get port dir successful."
 } -cleanup {
-    file delete -force $portdbpath
+    file delete -force $macports::portdbpath
 } -result "Get port dir successful."
 
 
@@ -416,83 +528,40 @@
 } -result "Mport open successful."
 
 
-test mportopen_installed {
-    Mport installed unit test.
-} -constraints {
-    root
-} -setup {
-    global os_platform os_version os_arch macosx_version pwd
-    global version mport portpath portbuildpath
+# Covered by mportopen_installed
+# test mportclose_installed
 
-    set os.platform darwin
-    set macosx_version 10.8
-    set os_version 11
-    set os_arch i386
-    set os.major 10
-    set supported_archs {}
-    set configure.build_arch build_arch
-    set portarchivetype tgz
 
-    set subport fondu
-    set version 3.0
-    set create $pwd/create
-    set portbuildpath $pwd
-    set destpath $pwd/work/destroot
-    set portpath $pwd
+test mporttraverse {
+    Mport traverse unit test. Uses 3rd column of the Portfile.
+} -setup {
+    file mkdir $pwd/porttree
+    file mkdir $pwd/porttree/cat1/fondu
+    file mkdir $pwd/porttree/cat2/fondu
 
-    file copy -force $pwd/Portfile /tmp/
-    set mport [mportopen file://.]
+    file copy -force $pwd/Portfile $pwd/porttree/cat1/fondu/Portfile
+    file copy -force $pwd/Portfile $pwd/porttree/cat2/fondu/Portfile
 
-    proc getportbuildpath {id {portname ""}} {
-	global portdbpath
-	regsub {://} $id {.} port_path
-	regsub -all {/} $port_path {_} port_path
-	return [file join $portdbpath build $port_path $portname]
+    proc test_proc {file} {
+	global pwd res
+	set fd [open ${pwd}/porttree/${file}/Portfile r]
+	gets $fd line
+	append res [lindex [split $line " "] 3]
     }
 
-    proc getportworkpath_from_buildpath {portbuildpath} {
-	return [file join $portbuildpath work]
+    global res
+    set res ""
+} -body {
+    mporttraverse test_proc $pwd/porttree
+    if {$res != "8547285472"} {
+	return "FAIL: porttree not traversed"
     }
-
-    proc getportworkpath_from_portdir {portpath {portname ""}} {
-	return [getportworkpath_from_buildpath [getportbuildpath $portpath $portname]]
-    }
-
-    source $pwd/../../port1.0/portmain.tcl
-
-    # sets up PortInfo array
-    if {[eval_variants variations] != 0} {
-	mportclose $mport
-	error "Error evaluating variants"
-    }
-
-    # set $version var
-    set workername [ditem_key $mport workername]
-
-    # run destroot
-    $workername eval eval_targets destroot
-
-    # portinstall setup
-    interp alias {} _cd {} cd
-    set macosx_deployment_target $pwd/deploy_target
-    file mkdir $pwd/$subport
-    file link -symbolic $pwd/$subport/work $pwd/work
-
-    if {[catch {portinstall::install_main}] != 0} {
-        return "FAIL: cannot install port"
-    }
-} -body {
+    return "Mport traverse successful."
 } -cleanup {
-    set res [uninstall_main]
-    mportclose $mport
+    file delete -force $pwd/porttree
+} -result "Mport traverse successful."
 
-    file delete -force $pwd/$subport/work
-    file delete -force $pwd/$subport
-} -result ""
 
-
-# test mportclose_installed
-# test mporttraverse
 # test _mportsearchpath
 # test _mportinstalled
 # test _mportactive
@@ -533,17 +602,191 @@
 # test upgrade
 # test _upgrade
 # test _upgrade_dependencies
-# test mportselect
-# test gettmpdir
-# test arch_runnable
+
+
+test mportselect {
+    Mport select unit test.
+} -setup {
+    set macports::prefix $pwd/prefix
+
+    file mkdir $macports::prefix/etc/select/group
+    set f1 [open $macports::prefix/etc/select/group/file1 w+]
+    set f2 [open $macports::prefix/etc/select/group/file2 w+]
+    set f3 [open $macports::prefix/srcs w+]
+    puts $f1 "srcs\n"
+    close $f1
+    close $f2
+    close $f3
+
+    set fd [open $macports::prefix/etc/select/group/base w+]
+    puts $fd "a\nb"
+    close $fd
+} -body {
+    if {[mportselect list group] != {file1 file2}} {
+	return "FAIL: files not listed"
+    }
+    if {[mportselect set group file1] != ""} {
+	reutrn "FAIL: cannot set links"
+    }
+    if {![file exists $macports::prefix/a]} {
+	return "FAIL: link not created"
+    }
+    if {[mportselect show group] != "file1"} {
+	return "FAIL: file not selected"
+    }
+    return "Mport select successful."
+} -cleanup {
+    file delete -force $macports::prefix
+} -result "Mport select successful."
+
+
+test gettmpdir {
+    Get tmp dir unit test.
+} -body {
+    global env
+    set env(TMPDIR) temporal
+    if {[macports::gettmpdir] != "temporal"} {
+	return "FAIL: set temp dir not detected"
+    }
+    unset env(TMPDIR)
+    if {[macports::gettmpdir] != "/tmp"} {
+	return "FAIL: default value not set"
+    }
+    return "Get tmp dir successful."
+} -result "Get tmp dir successful."
+
+
+test arch_runnable {
+    Arch runnable unit test.
+} -body {
+    set macports::os_major 12
+    set macports::os_arch i386
+    set macports::os_platform darwin
+    if {[macports::arch_runnable ppc1] != no} {
+	return "FAIL: major:12 arch:i386 arch:ppc* not detected"
+    }
+    if {[macports::arch_runnable ppc64] != no} {
+	return "FAIL: major:12 arch:i386 arch:ppc64 not detected"
+    }
+    set macports::os_major 7
+    set macports::os_arch i386
+    set macports::os_platform darwin
+    if {[macports::arch_runnable x86_64] != no} {
+	return "FAIL: major:7 arch:i386 arch:x86_64 not detected"
+    }
+    set macports::os_major 12
+    set macports::os_arch i386
+    set macports::os_platform darwin
+    if {[macports::arch_runnable x86_64] != yes} {
+	return "FAIL: major:12 arch:i386 arch:x86_64 not detected"
+    }
+    return "Arch runnable successful."
+} -result "Arch runnable successful."
+
+
 # test revupgrade
 # test revupgrade_scanandrebuild
-# test path_is_in_prefix
-# test revupgrade_handle_special_paths
+
+
+test path_is_in_prefix {
+    Path is in prefix unit test.
+} -body {
+    set macports::applications_dir appdir
+    if {[macports::path_is_in_prefix appdir/test/port] != yes} {
+	return "FAIL: application dir not detected"
+    }
+    set macports::prefix prefix
+    if {[macports::path_is_in_prefix prefix/test/port] != yes} {
+	return "FAIL: prefix not detected"
+    }
+    if {[macports::path_is_in_prefix test/port] != no} {
+	return "FAIL: no prefix detected"
+    }
+    return "Path prefix successful."
+} -result "Path prefix successful."
+
+
+test revupgrade_handle_special_paths {
+    Revupgrade handle special paths unit test.
+} -body {
+    set res [macports::revupgrade_handle_special_paths fname test_path]
+    if {$res != "test_path"} {
+	return "FAIL: wrong path"
+    }
+    set res [macports::revupgrade_handle_special_paths fname @loader_path/test_load]
+    if {$res != "./test_load"} {
+	return "FAIL: wrong load path"
+    }
+    return "Revupgrade handle special path successful."
+} -result "Revupgrade handle special path successful."
+
+
 # test revupgrade_buildgraph
-# test get_pingtime
-# test set_pingtime
-# test get_archive_sites_conf_values
 
 
+test get_pingtime {
+    Get ping time unit test.
+} -setup {
+    set time [expr [clock seconds] - 86300]
+    set macports::ping_cache(macports.org) [list MacPorts $time]
+    set macports::host_blacklisted(macports_blacklist) [list black $time]
+    set macports::host_preferred(macports_pref) [list pref $time]
+
+} -body {
+    if {[macports::get_pingtime macports.org] != "MacPorts"} {
+	return "FAIL: wrong ping time"
+    }
+    if {[macports::get_pingtime macports_blacklist] != -1} {
+	return "FAIL: wrong time for blacklisted host"
+    }
+    if {[macports::get_pingtime macports_pref] != 1} {
+	return "FAIL: wrong time for preferred host"
+    }
+    return "Get ping time successful."
+} -result "Get ping time successful."
+
+
+test set_pingtime {
+    Set ping time unit test.
+} -body {
+    set macports::ping_cache(macports) {}
+    if {[lindex [macports::set_pingtime macports 007] 0] != 007} {
+	return "FAIL: ping time not set"
+    }
+    return "Set ping time successful."
+} -result "Set ping time successful."
+
+
+test get_archive_sites_conf_values {
+    Get archive sites conf values unit test.
+} -setup {
+    file mkdir $pwd/archive_sites
+    set fd [open $pwd/archive_sites/archive_sites.conf w+]
+    puts $fd "name fondu"
+    puts $fd "urls macports.org"
+    puts $fd "type tgz"
+    close $fd
+
+    set macports::autoconf::macports_conf_path $pwd/archive_sites
+
+} -body {
+    set res [macports::get_archive_sites_conf_values]
+    if {[lindex [split $res " "] 1] != "macports.org:nosubdir"} {
+	return "FAIL: name not set"
+    }
+    if {[lindex [split $res " "] 3] != "tgz"} {
+	return "FAIL: wrong type set"
+    }
+
+    set macports::archive_sites_conf_values {a b c}
+    if {[macports::get_archive_sites_conf_values] != {a b c}} {
+	return "FAIL: wrong  result for bad conf file"
+    }
+    return "Get archive sites conf values successful."
+
+} -cleanup {
+    file delete -force $pwd/archive_sites
+} -result "Get archive sites conf values successful."
+
+
 cleanupTests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130819/3b312969/attachment-0001.html>


More information about the macports-changes mailing list