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

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

use proper testConstraint to avoid running trace mode test on unsupported platforms, and add darwin platform constraint to a couple tests that need it

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