[108387] branches/gsoc13-tests/src/port1.0/tests/portclean.test
marius at macports.org
marius at macports.org
Mon Jul 22 03:31:56 PDT 2013
Revision: 108387
https://trac.macports.org/changeset/108387
Author: marius at macports.org
Date: 2013-07-22 03:31:56 -0700 (Mon, 22 Jul 2013)
Log Message:
-----------
portclean.test: added all needed tests
Added Paths:
-----------
branches/gsoc13-tests/src/port1.0/tests/portclean.test
Added: branches/gsoc13-tests/src/port1.0/tests/portclean.test
===================================================================
--- branches/gsoc13-tests/src/port1.0/tests/portclean.test (rev 0)
+++ branches/gsoc13-tests/src/port1.0/tests/portclean.test 2013-07-22 10:31:56 UTC (rev 108387)
@@ -0,0 +1,216 @@
+package require tcltest 2
+namespace import tcltest::*
+
+set pwd [file normalize $argv0]
+set pwd [eval file join {*}[lrange [file split $pwd] 0 end-1]]
+
+package require macports 1.0
+mportinit
+
+source ../portclean.tcl
+
+proc getportlogpath {id {portname ""}} {
+ global macports::portdbpath
+ regsub {://} $id {.} port_path
+ regsub -all {/} $port_path {_} port_path
+ return [file join $portdbpath logs $port_path $portname]
+}
+
+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] == 0} {
+ return ${cmd_path}
+ } else {
+ return -code error "${result} or at its MacPorts guration time location, did you move it?"
+ }
+ }
+}
+
+# Actual test cases
+
+test clean_start {
+ Clean start unit test.
+} -body {
+ if {[getuid] != 0} {return "FAIL: not root, skipping test"}
+
+ set prefix /opt/local
+ seteuid 333
+ if {[catch {clean_start args}] != 1} {
+ return "FAIL: couldn't elevate privileges"
+ }
+ seteuid 0
+ return "Clean_start successful."
+} -result "Clean_start successful."
+
+
+# test clean_main
+
+
+test clean_dist {
+ Clean distfiles unit test.
+} -body {
+ set usealtworkpath no
+ set ports_force yes
+ set portdbpath $pwd/dbpath
+ set altprefix /tmp/altprefix
+ set dist_subdir subdir
+ set name subdir_name
+ set distpath $pwd/distpath
+ lappend distfiles $distpath/dist_file
+ lappend distfiles $distpath/dist_file2
+ set patchpath $pwd/patchpath
+ lappend patchfiles $patchpath/patch_file
+ lappend patchfiles $patchpath/patch_file2
+
+ # create files
+ file mkdir $distpath
+ close [open $distpath/dist_file w+]
+ close [open $distpath/dist_file2 w+]
+ file mkdir $altprefix$distpath
+ close [open $altprefix$distpath/dist_file2 w+]
+ file mkdir $portdbpath/distfiles/$dist_subdir
+ close [open $portdbpath/distfiles/$dist_subdir/subdir_file w+]
+ close [open $portdbpath/distfiles/$dist_subdir/subdir_$name w+]
+
+ # create patch files
+ file mkdir $patchpath
+ close [open $patchpath/patch_file2 w+]
+ file mkdir $altprefix$patchpath
+ close [open $altprefix$patchpath/patch_file2 w+]
+
+ portclean::clean_dist
+
+ if {[file exists $distpath/dist_file]} {
+ return "FAIL: distfile not removed"
+ }
+ if {[file exists $distpath/dist_file2]} {
+ return "FAIL: distfile not removed"
+ }
+ if {[file exists $altprefix$distpath/dist_file2]} {
+ return "FAIL: alt distfile not removed"
+ }
+ if {[file exists $patchpath/patch_file2]} {
+ return "FAIL: patchfile not removed"
+ }
+ if {[file exists $altprefix$patchpath/patch_file2]} {
+ return "FAIL: alt patchfile not removed"
+ }
+ if {[file exists $portdbpath/distfiles/$dist_subdir]} {
+ return "FAIL: distfiles dir not removed"
+ }
+
+ return "Clean distfiles successful."
+
+} -cleanup {
+ file delete -force $distpath
+ file delete -force $portdbpath
+ file delete -force $patchpath
+ file delete -force $altprefix
+
+} -result "Clean distfiles successful."
+
+
+test clean_work {
+ Clean work unit test.
+} -body {
+ set usealtworkpath no
+ set altprefix $pwd/prefix
+ set portpath portpath
+ set subbuildpath /subbuild
+ set worksymlink $pwd/symlink
+
+ # create files
+ file mkdir $subbuildpath
+ close [open $subbuildpath/test.work w+]
+ file mkdir $altprefix/subbuild
+ close [open $altprefix/subbuild/test.work w+]
+ close [open $altprefix/$portpath w+]
+ file link -symbolic $worksymlink $subbuildpath
+
+ portclean::clean_work
+
+ if {[file exists $subbuildpath]} {
+ return "FAIL: buildpath not removed"
+ }
+ if {[file exists $altprefix/subbuild]} {
+ return "FAIL: subbuild not removed"
+ }
+ if {[file exists $worksymlink]} {
+ return "FAIL: symlink not removed"
+ }
+ if {[file exists $altprefix$portpath]} {
+ return "FAIL: port dir in alt prefix not removed"
+ }
+
+ return "Clean work successful."
+
+} -cleanup {
+ file delete -force $subbuildpath
+ file delete -force $altprefix
+ file delete -force $worksymlink
+
+} -result "Clean work successful."
+
+
+test clean_logs {
+ Clean logs unit test.
+} -body {
+ set portpath $pwd/portpath
+ set logpath [getportlogpath $portpath]
+ set subport $logpath/subport
+
+ # create files
+ file mkdir $subport
+ close [open $subport/test.log w+]
+
+ portclean::clean_logs
+
+ if {[file exists $subport]} {
+ return "FAIL: log dir not removed"
+ }
+ return "Clean logs successful."
+
+} -cleanup {
+ file delete -force $portpath
+ file delete -force $subport
+
+} -result "Clean logs successful."
+
+
+test clean_archive {
+ Clean archive unit test.
+} -body {
+ set subport subport
+ set portdbpath $pwd/dbpath
+
+ file mkdir $portdbpath/incoming
+ close [open $portdbpath/incoming/test.clean w+]
+ close [open $portdbpath/incoming/subport-1_0.0.0.0.TMP w+]
+
+ # create zip
+ #close [open $pwd/+CONTENTS w+]
+ #exec zip $portdbpath/incoming/subport-2_0.0.0.0.zip $pwd/+CONTENTS
+
+ close stderr
+ portclean::clean_archive
+ errorChannel [open /dev/null w]
+
+ if {[file exists $portdbpath/incoming/subport-1_0.0.0.0.TMP]} {
+ return "FAIL: .TMP file not removed"
+ }
+ if {![file exists $portdbpath/incoming/test.clean]} {
+ return "FAIL: removed unrelated file"
+ }
+
+ return "Clean archive successful."
+
+} -cleanup {
+ file delete -force $portdbpath
+ file delete -force $pwd/file2
+
+} -result "Clean archive successful."
+
+
+cleanupTests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20130722/4634da3c/attachment.html>
More information about the macports-changes
mailing list