source: branches/gsoc13-tests/tests/test/library.tcl @ 139170

Last change on this file since 139170 was 111323, checked in by marius@…, 7 years ago

Merge from trunk.

File size: 4.8 KB
Line 
1set autoconf [file dirname $argv0]/../../../Mk/macports.autoconf.mk
2eval ::tcltest::configure $::argv
3
4set output_file "output"
5set work_dir "work"
6
7# Set of procs used for testing.
8
9# Sets $bindir variable from macports.autoconf.mk
10# autogenerated file.
11proc load_variables {pwd} {
12    global autoconf
13    global bindir
14    global datadir
15    global portsrc
16    global cpwd
17
18    if { [file exists $autoconf] == 0 } {
19        puts "ERROR: $autoconf does not exist."
20        exit 1
21    }
22
23    set cpwd [eval file join {*}[lrange [file split $pwd] 0 end-2]]
24
25    set line [get_line $autoconf "prefix*"]
26    set prefix [lrange [split $line " "] 1 1]
27
28    set line [get_line $autoconf "bindir*"]
29    set bin [lrange [split $line "/"] 1 1]
30
31    set bindir $prefix/$bin/
32    set datadir $prefix/share
33    set portsrc $cpwd/test-macports.conf
34
35}
36
37proc cleanup {} {
38    global cpwd
39
40    file delete -force /tmp/macports-tests/
41    file delete -force $cpwd/PortIndex $cpwd/PortIndex.quick
42}
43
44# Sets initial directories
45proc set_dir {} {
46    global datadir
47    global cpwd
48
49    cleanup
50
51    file mkdir /tmp/macports-tests/ports
52    file mkdir /tmp/macports-tests/opt/local/etc/macports/
53    file mkdir /tmp/macports-tests/opt/local/share/
54    file mkdir /tmp/macports-tests/opt/local/var/macports/receipts/
55    file mkdir /tmp/macports-tests/opt/local/var/macports/registry/
56    file mkdir /tmp/macports-tests/opt/local/var/macports/build/
57
58    file link -symbolic /tmp/macports-tests/opt/local/share/macports $datadir/macports
59    file link -symbolic /tmp/macports-tests/ports/test $cpwd/test
60}
61
62# Run portindex
63proc port_index {} {
64    global bindir
65    global datadir
66    global cpwd
67
68    # Move up 2 level to run portindex.
69    set path [pwd]
70    cd ../..
71
72    set cmd "portindex"
73
74    set result [eval exec $bindir$cmd 2>@1]
75
76    file copy $cpwd/sources.conf /tmp/macports-tests/opt/local/etc/macports/
77    file copy $cpwd/PortIndex $cpwd/PortIndex.quick /tmp/macports-tests/ports/
78
79    cd $path
80}
81
82# Executes port clean.
83proc port_clean {pwd} {
84    global bindir
85    global datadir
86    global portsrc
87
88    set back [pwd]
89    cd $pwd
90
91    set env "env PORTSRC=${portsrc}"
92    set cmd "port"
93    set args "clean"
94
95    set result [catch {eval exec $env $bindir$cmd $args 2>@1} ]
96    cd $back
97}
98
99# Runs the portfile.
100proc port_run {pwd} {
101    global bindir
102    global datadir
103    global portsrc
104
105    set back [pwd]
106    cd $pwd
107
108    set env "env PORTSRC=${portsrc}"
109    set cmd "port"
110    set args "-d test"
111    set output "output"
112
113    set result [catch {eval exec $env $bindir$cmd $args >&output} ]
114    cd $back
115    return $result
116}
117
118# Runs port trace.
119proc port_trace {pwd} {
120    global bindir
121    global datadir
122    global portsrc
123
124    set back [pwd]
125    cd $pwd
126
127    set env "env PORTSRC=${portsrc}"
128    set cmd "port"
129    set args "-t test"
130    set output "output"
131
132    set result [catch {eval exec $env $bindir$cmd $args >&output 2>@1} ]
133    cd $back
134    return $result
135}
136
137# Installs new portfile.
138proc port_install {} {
139    global bindir
140    global portsrc
141
142    set env "env PORTSRC=${portsrc}"
143    set cmd "port"
144    set args "install"
145
146    set result [catch {eval exec $env $bindir$cmd $args > output 2>@1} ]
147}
148
149# Run configure command.
150proc port_config {pwd} {
151    global path
152    global bindir
153    global portsrc
154
155    set env "env PORTSRC=${portsrc}"
156    set cmd "port"
157    set args "configure"
158
159    set result [catch {eval exec $env $bindir$cmd $args 2>@1} ]
160}
161
162# Run desroot command.
163proc port_desroot {pwd} {
164    global path
165    global bindir
166    global portsrc
167    global work_dir
168    global output_file
169
170    set env "env PORTSRC=${portsrc}"
171    set cmd "port"
172    set args "destroot"
173
174    file copy -force $path/statefile $work_dir/.macports.statefile-unknown-version.state
175    if { [exec id -u] == 0 } {
176        exec chown macports $work_dir/.macports.statefile-unknown-version.state
177    }
178    set result [catch {eval exec $env $bindir$cmd $args >$output_file 2>@1} ]
179}
180
181# Uninstalls portfile.
182proc port_uninstall {} {
183    global bindir
184    global portsrc
185
186    set env "env PORTSRC=${portsrc}"
187    set cmd "port"
188    set args "uninstall"
189
190    set result [catch {eval exec $env $bindir$cmd $args > output 2>@1} ]
191}
192
193# Returns the line containint a given string
194# from a given file, or -1 if nothing is found.
195proc get_line {filename lookup} {
196    set fp [open $filename r]
197
198    while {[gets $fp line] != -1} {
199        set line [string tolower $line]
200
201        if {[string match $lookup $line] != 0} {
202            close $fp
203            return $line
204        }
205    }
206    return -1
207}
208
209# This proc contains all the steps necesary
210# to install a port and save the output to a file.
211# Needed for the majority of regression tests.
212proc initial_setup {} {
213    global output_file
214    global work_dir
215    global path
216
217    makeFile "" $output_file
218    makeDirectory $work_dir
219
220    load_variables $path
221    set_dir
222    port_index
223    port_clean $path
224    port_run $path
225}
Note: See TracBrowser for help on using the repository browser.