source: trunk/base/tests/test/library.tcl.in @ 134837

Last change on this file since 134837 was 134837, checked in by jmr@…, 5 years ago

replace eval with {*} in the last few applicable places

File size: 4.2 KB
Line 
1::tcltest::configure {*}$::argv
2
3set output_file "output"
4set work_dir "work"
5
6# constraint for tests that should only run on Darwin
7::tcltest::testConstraint darwin [expr {"@OS_PLATFORM@" eq "darwin"}]
8
9# constraint indicating whether the platform supports trace mode
10::tcltest::testConstraint tracemode_support [expr {@TRACEMODE_SUPPORT@ != 0}]
11
12# constraint for tests that use svn
13::tcltest::testConstraint has_svn [expr {"@SVN@" ne ""}]
14
15# Set of procs used for testing.
16
17# Sets $bindir variable from autoconf
18proc load_variables {pwd} {
19    global bindir datadir portsrc cpwd
20
21    set cpwd [file dirname [file dirname $pwd]]
22
23    set prefix "@prefix@"
24    set exec_prefix "@exec_prefix@"
25    set bindir "@bindir@"
26    set datadir "@datarootdir@"
27    set portsrc ${cpwd}/test-macports.conf
28
29}
30
31proc cleanup {} {
32    global cpwd
33
34    file delete -force /tmp/macports-tests
35    file delete -force ${cpwd}/PortIndex ${cpwd}/PortIndex.quick
36}
37
38# Sets initial directories
39proc set_dir {} {
40    global datadir cpwd
41
42    cleanup
43
44    file mkdir /tmp/macports-tests/ports \
45               /tmp/macports-tests/opt/local/etc/macports \
46               /tmp/macports-tests/opt/local/share \
47               /tmp/macports-tests/opt/local/var/macports/receipts \
48               /tmp/macports-tests/opt/local/var/macports/registry \
49               /tmp/macports-tests/opt/local/var/macports/build
50
51    file link -symbolic /tmp/macports-tests/opt/local/share/macports $datadir/macports
52    file link -symbolic /tmp/macports-tests/ports/test $cpwd/test
53}
54
55# Run portindex
56proc port_index {} {
57    global bindir datadir cpwd
58
59    # Move up 2 level to run portindex.
60    set path [pwd]
61    cd ../..
62    # Avoid warning about ports tree being old
63    exec sh -c {touch */*/Portfile}
64
65    exec ${bindir}/portindex 2>@1
66
67    file copy ${cpwd}/sources.conf /tmp/macports-tests/opt/local/etc/macports/
68    file copy ${cpwd}/PortIndex ${cpwd}/PortIndex.quick /tmp/macports-tests/ports/
69
70    cd $path
71}
72
73# Executes port clean.
74proc port_clean {pwd} {
75    global bindir datadir portsrc
76
77    set back [pwd]
78    cd $pwd
79
80    catch {exec env PORTSRC=${portsrc} ${bindir}/port clean 2>@1}
81    cd $back
82}
83
84# Runs the portfile.
85proc port_run {pwd} {
86    global bindir datadir portsrc
87
88    set back [pwd]
89    cd $pwd
90
91    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port -d -N test >&output} ]
92    cd $back
93    return $result
94}
95
96# Runs port trace.
97proc port_trace {pwd} {
98    global bindir datadir portsrc
99
100    set back [pwd]
101    cd $pwd
102
103    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port -t test >&output 2>@1} ]
104    cd $back
105    return $result
106}
107
108# Installs new portfile.
109proc port_install {} {
110    global bindir portsrc
111
112    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port install > output 2>@1} ]
113}
114
115# Run configure command.
116proc port_config {pwd} {
117    global path bindir portsrc
118
119    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port configure 2>@1} ]
120}
121
122# Run destroot command.
123proc port_destroot {pwd} {
124    global path bindir portsrc work_dir output_file
125
126    file copy -force ${path}/statefile ${work_dir}/.macports.statefile-unknown-version.state
127    if { [exec id -u] == 0 } {
128        exec chown macports ${work_dir}/.macports.statefile-unknown-version.state
129    }
130    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port destroot >$output_file 2>@1} ]
131}
132
133# Uninstalls portfile.
134proc port_uninstall {} {
135    global bindir portsrc
136
137    set result [catch {exec env PORTSRC=${portsrc} ${bindir}/port uninstall > output 2>@1} ]
138}
139
140# Returns the line containint a given string
141# from a given file, or -1 if nothing is found.
142proc get_line {filename lookup} {
143    set fp [open $filename r]
144
145    while {[gets $fp line] != -1} {
146        set line [string tolower $line]
147
148        if {[string match $lookup $line] != 0} {
149            close $fp
150            return $line
151        }
152    }
153    return -1
154}
155
156# This proc contains all the steps necesary
157# to install a port and save the output to a file.
158# Needed for the majority of regression tests.
159proc initial_setup {} {
160    global output_file work_dir path
161
162    makeFile "" $output_file
163    makeDirectory $work_dir
164
165    load_variables $path
166    set_dir
167    port_index
168    port_clean $path
169    port_run $path
170}
Note: See TracBrowser for help on using the repository browser.