source: trunk/base/src/macports1.0/tests/macports.test @ 146710

Last change on this file since 146710 was 146710, checked in by raimue@…, 4 years ago

macports1.0/tests: Move initialization of custom prefix to library

File size: 27.3 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2
3package require tcltest 2
4namespace import tcltest::*
5::tcltest::configure {*}$::argv
6
7set pwd [file dirname [file normalize $argv0]]
8
9source ../macports_test_autoconf.tcl
10
11# constraint for darwin platform
12testConstraint darwin [expr {$macports::autoconf::os_platform eq "darwin"}]
13
14package require macports 1.0
15package require Thread
16
17source ./library.tcl
18
19# clean leftovers from interrupted tests
20file delete -force $pwd/tmpdir
21# use a local, temporary prefix for testing
22init_tmp_prefix $pwd $pwd/tmpdir
23
24# Debug options
25array set ui_options {}
26#set ui_options(ports_debug)   yes
27#set ui_options(ports_verbose) yes
28mportinit ui_options
29
30
31test mportclose {
32    Mport close unit test.
33} -setup {
34    set mport [mportopen file://${pwd}]
35} -body {
36    if {[catch {mportclose $mport}] != 0} {
37       return "FAIL: cannot run mportclose"
38    }
39    if {[ditem_key $mport workername] ne ""} {
40       return "FAIL: port not closed"
41    }
42    return "Mport close successful."
43} -cleanup {
44    catch {mportclose $mport}
45} -result "Mport close successful."
46
47
48test mportinfo {
49    Mport info unit test.
50} -setup {
51    set mport [mportopen file://${pwd}]
52} -body {
53    set res [mportinfo $mport]
54    catch {array set PortInfo $res}
55    if {![info exists PortInfo(canonical_active_variants)]} {
56        return "FAIL: cannot get ::PortInfo"
57    }
58    return "Mport info successful."
59} -cleanup {
60    mportclose $mport
61} -result "Mport info successful."
62
63
64test worker_init {
65    Worker init unit test.
66} -setup {
67    set name [interp create]
68    set portpath $pwd/portpath
69    set porturl http://www.macports.org
70    set portbuildpath $pwd/build
71    set options {a b}
72    set variations {1 2}
73} -body {
74    macports::worker_init $name $portpath $porturl $portbuildpath $options $variations
75    if {$name ne "interp0"} {
76       return "FAIL: wrong workername"
77    }
78    if {[catch {$name eval source Portfile} result]} {
79       return "FAIL: cannot load Portfile"
80    }
81    if {[$name eval findBinary ls] ne "/bin/ls"} {
82       return "FAIL: alias not created"
83    }
84    if {[$name eval return \$os_arch] ne $macports::os_arch} {
85       return "FAIL: var not set"
86    }
87    return "Worker init successful."
88} -result "Worker init successful."
89
90
91test init_logging {
92    Init logging unit test.
93} -constraints {
94    root
95} -setup {
96    set mport [mportopen file://${pwd}]
97} -body {
98    if {[macports::init_logging $mport] != 0} {
99       return "FAIL: incorrect channels"
100    }
101    return "Init logging successful."
102} -cleanup {
103    mportclose $mport
104} -result "Init logging successful."
105
106
107test ui_isset {
108    Ui is set unit test.
109} -body {
110    namespace eval macports {
111    array set ui_options { test yes }
112    }
113    if {[macports::ui_isset test] != 1} {
114       return "FAIL: set option not detected"
115    }
116    if {[macports::ui_isset port] != 0} {
117       return "FAIL: unset option detected"
118    }
119    return "ui_isset successful."
120} -result "ui_isset successful."
121
122
123test global_option_isset {
124    Global option is set unit test.
125} -body {
126    namespace eval macports {
127    array set global_options { test yes }
128    }
129    if {[macports::global_option_isset test] != 1} {
130       return "FAIL: set option not detected"
131    }
132    if {[macports::global_option_isset port] != 0} {
133       return "FAIL: unset option detected"
134    }
135    return "Global option isset successful."
136} -result "Global option isset successful."
137
138
139test ch_logging {
140    Channel logging unit test. Assumes main.log filename.
141} -constraints {
142    root
143} -setup {
144    set mport [mportopen file://${pwd}]
145
146    set portname [_mportkey $mport subport]
147    set portpath [_mportkey $mport portpath]
148    set logname [macports::getportlogpath $portpath $portname]
149    file delete -force $logname
150
151} -body {
152    if {[macports::ch_logging $mport] != 0} {
153       return "FAIL: channels not set"
154    }
155    if {![file exists $logname]} {
156       return "FAIL: logname dir missing"
157    }
158    if {![file exists $logname/main.log]} {
159       return "FAIL: main.log missing"
160    }
161    return "Channel logging successful."
162
163} -cleanup {
164    mportclose $mport
165} -result "Channel logging successful."
166
167
168test push_log {
169    Push log unit test.
170} -constraints {
171    root
172} -setup {
173    set mport [mportopen file://${pwd}]
174    set ::logenabled 1
175} -body {
176    if {[catch {macports::push_log $mport}] != 0} {
177       return "FAIL: cannot push log"
178    }
179    if {[lindex $::logstack 0] != [list $::debuglog $::debuglogname]} {
180       return "FAIL: incorrect logstack"
181    }
182    return "Push log successful."
183} -cleanup {
184    mportclose $mport
185} -result "Push log successful."
186
187
188test pop_log {
189    Pop log unit test.
190} -setup {
191    set ::logenabled 1
192    set ::logstack [open $pwd/logstack w+]
193    set ::debuglog [open $pwd/log w+]
194    set mport [mportopen file://${pwd}]
195    if {[catch {macports::push_log $mport}] != 0} {
196       return "FAIL: cannot push log"
197    }
198} -body {
199    macports::pop_log
200    if {$::debuglog ne $::logstack} {
201        return "FAIL: cannot pop log"
202    }
203    return "Pop log successful."
204} -cleanup {
205    unset ::logenabled
206    unset ::logstack
207    unset ::debuglog
208    mportclose $mport
209    file delete -force $pwd/log
210    file delete -force $pwd/logstack
211} -result "Pop log successful."
212
213
214test set_phase {
215    Set phase unit test.
216} -body {
217    set res [set_phase test]
218    if {$macports::current_phase ne "test"} {
219        return "FAIL: phase not set"
220    }
221    return "Set phase successful."
222} -result "Set phase successful."
223
224
225test ui_message {
226    UI message unit test.
227} -setup {
228    set fd [open $pwd/message w]
229    set fd2 [open $pwd/log w]
230    set macports::channels(0) $fd
231    set macports::current_phase test
232    set ::debuglog $fd2
233} -body {
234    set res [ui_message 0 prefix args]
235    close $fd
236    close $fd2
237
238    set fd [open $pwd/message r]
239    set fd2 [open $pwd/log r]
240    set line [read $fd]
241    if {$line ne "prefixargs\n"} {
242        return "FAIL: wrong message: $line"
243    }
244    set line [read $fd2]
245    if {$line ne ":0:test args\n"} {
246        return "FAIL: wrong log: $line"
247    }
248    close $fd
249    close $fd2
250
251    set fd [open $pwd/message w]
252    set fd2 [open $pwd/log w]
253    set res [ui_message 0 prefix -nonewline arg]
254    close $fd
255    close $fd2
256
257    set fd [open $pwd/message r]
258    set fd2 [open $pwd/log r]
259    set line [read $fd]
260    if {$line ne "prefixarg"} {
261        return "FAIL: wrong message: $line"
262    }
263    set line [read $fd2]
264    if {$line ne ":0:test arg"} {
265        return "FAIL: wrong log: $line"
266    }
267    close $fd
268    close $fd2
269
270    return "UI message successful."
271} -cleanup {
272    file delete -force $pwd/log
273    file delete -force $pwd/message
274} -result "UI message successful."
275
276
277# test ui_init
278
279
280test ui_prefix_default {
281    UI prefix default unit test.
282} -body {
283    if {[macports::ui_prefix_default debug] ne {DEBUG: }} {
284        return "FAIL: wrong prefix"
285    }
286    if {[macports::ui_prefix_default error] ne {Error: }} {
287        return "FAIL: wrong prefix"
288    }
289    if {[macports::ui_prefix_default warn] ne {Warning: }} {
290        return "FAIL: wrong prefix"
291    }
292    if {[macports::ui_prefix_default default] ne {}} {
293        return "FAIL: wrong prefix"
294    }
295    return "UI prefix default successful."
296} -result "UI prefix default successful."
297
298
299test ui_channels_default {
300    UI channels default unit test.
301} -setup {
302    set macports::ui_options(ports_debug) yes
303    set macports::ui_options(ports_verbose) yes
304    set macports::ui_options(ports_quiet) yes
305} -body {
306    if {[macports::ui_channels_default debug] ne {stderr}} {
307        return "FAIL: stderr not set"
308    }
309    if {[macports::ui_channels_default info] ne {stdout}} {
310        return "FAIL: stdout not set"
311    }
312    if {[macports::ui_channels_default notice] ne {}} {
313        return "FAIL: channel not set"
314    }
315    if {[macports::ui_channels_default msg] ne {stdout}} {
316        return "FAIL: channel not set"
317    }
318    if {[macports::ui_channels_default warn] ne {stderr}} {
319        return "FAIL: channel not set"
320    }
321    if {[macports::ui_channels_default error] ne {stderr}} {
322        return "FAIL: channel not set"
323    }
324    if {[macports::ui_channels_default default] ne {stdout}} {
325        return "FAIL: channel not set"
326    }
327    return "UI channels default successful."
328} -result "UI channels default successful."
329
330
331test ui_warn_once {
332    UI warn once unit test.
333} -setup {
334    # suppress test warning to avoid noise on terminal output
335    set channel_saved $macports::channels(warn)
336    set macports::channels(warn) {}
337} -body {
338    set res [ui_warn_once 0 test]
339
340    if {$macports::warning_done(0) != 1} {
341        return "FAIL: warning flag not set"
342    }
343    return "UI warn once successful."
344} -cleanup {
345    set macports::channels(warn) $channel_saved
346} -result "UI warn once successful."
347
348
349# Replace puts to catch errors
350# test puts
351
352
353test findBinary {
354    Find binary unit test.
355} -body {
356    if {[macports::findBinary pwd ls] ne "/bin/pwd"} {
357       return "FAIL: wrong binary"
358    }
359    if {[macports::findBinary pwd /bin/ls] ne "/bin/ls"} {
360       return "FAIL: wrong binary"
361    }
362    return "Find binary successful."
363} -result "Find binary successful."
364
365
366test binaryInPath {
367    Binary in path unit test.
368} -body {
369    if {[catch {macports::binaryInPath zz}] != 1} {
370       return "FAIL: invalid binary found"
371    }
372    if {[macports::binaryInPath ls] ne "/bin/ls"} {
373       return "FAIL: wrong binary found"
374    }
375    return "Binary in path successful."
376} -result "Binary in path successful."
377
378
379test getoption {
380    Get option unit test.
381} -body {
382    set macports::test macports
383    if {[macports::getoption test] ne "macports"} {
384        return "FAIL: cannot get option"
385    }
386    return "Get option successful."
387} -result "Get option successful."
388
389
390test setxcodeinfo {
391    Set XCode info unit test.
392} -constraints {
393    root
394} -setup {
395    unset macports::xcodeversion
396} -body {
397    if {[macports::setxcodeinfo a b c] ne ""} {
398       return "FAIL: xcode binary not found"
399    }
400    if {![info exists macports::xcodeversion]} {
401       return "FAIL: xcodeversion unset"
402    }
403    return "Set XCode version successful."
404} -result "Set XCode version successful."
405
406
407test set_developer_dir {
408    Set developer dir unit test. Tests only for correct xcode-select dir.
409} -constraints {
410    root
411} -body {
412    unset macports::developer_dir
413
414    if {[macports::set_developer_dir a b c] ne ""} {
415       return "FAIL: cannot set dev dir"
416    }
417    if {![info exists macports::developer_dir]} {
418       return "FAIL: developer_dir var no set"
419    }
420    return "Set developer dir successful."
421} -result "Set developer dir successful."
422
423
424test _is_valid_developer_dir {
425    Check valid dev dir unit test.
426} -constraints {
427    darwin
428} -body {
429    if {[macports::_is_valid_developer_dir $macports::developer_dir] != 1} {
430       return "FAIL: valid dir not detected"
431    }
432    return "Valid dev dir successful."
433} -result "Valid dev dir successful."
434
435
436# test mportinit
437
438
439test mportopen_installed {
440    Mport installed unit test.
441} -constraints {
442    root
443} -setup {
444    set subport gcc_select
445    set version 0.1
446    set revision 4
447
448    set mport [mportopen file://${pwd}]
449
450    # run destroot
451    mportexec $mport destroot
452
453    if {[catch {mportexec $mport activate}] != 0} {
454        ui_debug "$::errorInfo"
455        return "FAIL: cannot install port"
456    }
457
458    set variants {}
459    set options {}
460
461} -body {
462    set res [mportopen_installed $subport $version $revision $variants $options]
463    if {![string match "ditem_*" $res]} {
464       return "FAIL: installed port not opened"
465    }
466
467    if {[catch {mportclose $res}] != 0} {
468       return "FAIL: cannot close port"
469    }
470    if {[catch {mportclose $res}] != 1} {
471       return "FAIL: installed port not closed"
472    }
473    return "Installed port open successful."
474
475} -cleanup {
476    if {[catch {mportexec $mport uninstall}] != 0} {
477        return "FAIL: cannot uninstall port"
478    }
479    mportclose $mport
480
481    file delete -force $pwd/work
482    file delete -force $pwd/$subport
483    cd $pwd
484} -result "Installed port open successful."
485
486
487test mportshutdown {
488    Mport shutdown unit test.
489} -setup {
490    unset macports::ping_cache
491
492    set time [expr [clock seconds] - 86100]
493    set time_exp [expr [clock seconds] - 87000]
494    set macports::portdbpath $pwd/portdbpath
495    set macports::ping_cache(host1) [list test $time]
496    set macports::ping_cache(host2) [list test $time_exp]
497
498    file mkdir $macports::portdbpath
499    close [open $macports::portdbpath/pingtimes w+]
500
501} -body {
502    if {[mportshutdown] ne ""} {
503       return "FAIL: errors occured"
504    }
505
506    set res ""
507    append res "host1 \{test " $time "\}"
508    set fd [open $macports::portdbpath/pingtimes r]
509
510    if {[gets $fd] ne $res} {
511       return "FAIL: wrong value saved"
512    }
513    close $fd
514    return "Mportshutdown successful."
515
516} -cleanup {
517    file delete -force $macports::portdbpath
518} -result "Mportshutdown successful."
519
520
521test copy_xcode_plist {
522    Copy xcode plist unit test.
523} -constraints {
524    root
525} -body {
526    set target $pwd/target
527
528    if {[macports::copy_xcode_plist $target] ne ""} {
529       return "FAIL: cannot copy xcode plist"
530    }
531    if {![file exists $target/Library/Preferences/com.apple.dt.Xcode.plist]} {
532       return "FAIL: missing plist file"
533    }
534    return "Copy xcode plist successful."
535} -cleanup {
536    file delete -force $target
537} -result "Copy xcode plist successful."
538
539
540test create_thread {
541    Create thread unit test.
542} -body {
543    unset macports::portinterp_options
544    set macports::portinterp_options {a b}
545
546    set res [macports::create_thread]
547    if {![string match "tid0x*" $res]} {
548       return "FAIL: cannot create thread"
549    }
550    return "Create thread successful."
551} -result "Create thread successful."
552
553
554test get_tar_flags {
555    Get tar flags unit test.
556} -body {
557    if {[macports::get_tar_flags .tbz2] ne "-j"} {
558        return "FAIL: wrong flaga (-j)"
559    }
560    if {[macports::get_tar_flags .tgz] ne "-z"} {
561        return "FAIL: wrong flaga (-z)"
562    }
563    return "Get tar flags successful."
564} -result "Get tar flags successful."
565
566
567test fetch_port {
568    Fetch port unit test.
569} -body {
570    set url http://packages.macports.org/db_select/db_select-0.1_3.darwin_14.noarch.tbz2
571    set res [macports::fetch_port $url]
572    if {$res ne "${pwd}/portdbpath/portdirs/db_select-0.1_3"} {
573        return "FAIL: cannot fetch port"
574    }
575    return "Fetch port successful."
576} -cleanup {
577    file delete -force $pwd/portdbpath
578} -result "Fetch port successful."
579
580
581test getprotocol {
582    Get protocol unit test.
583} -body {
584    if {[macports::getprotocol http://www.macports.org] ne "http"} {
585       return "FAIL: wrong protocol"
586    }
587    return "Get protocol successful."
588} -result "Get protocol successful."
589
590
591test getportdir {
592    Get port directory unit test.
593} -setup {
594    close [open $pwd/local_file w+]
595} -body {
596    set url http://packages.macports.org/db_select/db_select-0.1_3.darwin_14.noarch.tbz2
597    set res [macports::getportdir $url]
598    set expected ${pwd}/portdbpath/portdirs/db_select-0.1_3
599    if {$res ne $expected} {
600            return "FAIL: incorrect port directory $res (expected $expected)"
601    }
602
603    set url file://${pwd}/local_file
604    set res [macports::getportdir $url]
605    set expected ${pwd}/portdbpath/portdirs/local_file
606    if {$res ne $expected} {
607            return "FAIL: incorrect local port directory $res (expected $expected)"
608    }
609    return "Get port dir successful."
610} -cleanup {
611    file delete -force $pwd/portdbpath
612    file delete -force $pwd/local_file
613} -result "Get port dir successful."
614
615
616test getportresourcepath {
617    Get port resource path. Doesn't check for 'file' protocol.
618} -body {
619    set macports::portdbpath $pwd/portdbpath
620    set url "http://packages.macports.org/db_select/db_select-0.1_3.darwin_14.noarch.tbz2"
621    set default_path $pwd/portdbpath/sources/rsync.macports.org/release/tarballs/ports/_resources
622    set fallback_path $pwd/portdbpath/sources/packages.macports.org/db_select/db_select-0.1_3.darwin_14.noarch.tbz2/_resources
623
624    if {[macports::getportresourcepath $url "" yes] ne $default_path} {
625       return "FAIL: wrong resource path"
626    }
627    if {[macports::getportresourcepath $url "" no] ne $fallback_path} {
628       return "FAIL: wrong fallback path"
629    }
630    if {[macports::getportresourcepath $url "test" no] ne "${fallback_path}/test"} {
631       return "FAIL: wrong fallback path with subdir"
632    }
633
634    return "Get resource path successful."
635} -result "Get resource path successful."
636
637
638test getdefaultportresourcepath {
639    Get default port resource path unit test.
640} -body {
641    set path test/path
642    set macports::sources_default file://$pwd
643    if {[macports::getdefaultportresourcepath $path] ne "${pwd}/_resources/${path}"} {
644       return "FAIL: wrong file res path"
645    }
646
647    set macports::sources_default http://$pwd
648    set default_source_url [lindex ${macports::sources_default} 0]
649    set right_path [macports::getsourcepath $default_source_url]/_resources/test/path
650    if {[macports::getdefaultportresourcepath $path] ne $right_path} {
651       return "FAIL: wrong http res path"
652    }
653    return "Default res path successful."
654} -result "Default res path successful."
655
656
657# test mportopen
658
659
660test mporttraverse {
661    Mport traverse unit test. Uses 3rd line of the Portfile.
662} -setup {
663    file mkdir $pwd/porttree
664    file mkdir $pwd/porttree/cat1/gcc_select
665    file mkdir $pwd/porttree/cat2/gcc_select
666
667    file copy -force $pwd/Portfile $pwd/porttree/cat1/gcc_select/Portfile
668    file copy -force $pwd/Portfile $pwd/porttree/cat2/gcc_select/Portfile
669
670    proc test_proc {file} {
671       global pwd res
672       set fd [open ${pwd}/porttree/${file}/Portfile r]
673       gets $fd
674       gets $fd
675       gets $fd line
676       append res [lindex [split $line " "] 1]
677    }
678
679    global res
680    set res ""
681} -body {
682    mporttraverse test_proc $pwd/porttree
683    if {$res ne "1.01.0"} {
684       return "FAIL: porttree not traversed"
685    }
686    return "Mport traverse successful."
687} -cleanup {
688    file delete -force $pwd/porttree
689} -result "Mport traverse successful."
690
691
692# test _mportsearchpath
693# test _mportinstalled
694# test _mportactive
695# test _portnameactive
696# test _mportispresent
697# test _mporterrorifconflictsinstalled
698# test _mportexec
699# test mportexec
700# test _upgrade_mport_deps
701# test _get_registry_archs
702# test getsourcepath
703# test _source_is_snapshot
704# test getportbuildpath
705# test getportlogpath
706# test getportworkpath_from_buildpath
707# test getportworkpath_from_portdir
708# test getindex
709
710
711# The test files might themselves be under version control, so the test
712# repositories need to live somewhere else.
713# TODO: Replace with "file tempfile" when we move to Tcl 8.6.
714package require fileutil 1.5.1-
715set tempdir [::fileutil::tempdir]
716
717
718testConstraint hasSvn [expr {
719    ![catch {macports::findBinary svn} svn] &&
720    ![catch {macports::findBinary svnadmin} svnadmin]
721}]
722
723test GetVCSUpdateCmd-svn {
724    Tests GetVCSUpdateCmd on a valid Subversion repository
725} -constraints {
726    hasSvn
727} -setup {
728    set repo [makeDirectory macports-test-svn-repo $tempdir]
729    exec $svnadmin create $repo
730    set wc [makeDirectory macports-test-svn-wc $tempdir]
731    # This URL should probably be encoded.
732    exec $svn checkout file://$repo $wc
733} -body {
734    string map [list $svn SVN $wc WC] [macports::GetVCSUpdateCmd $wc]
735} -cleanup {
736    removeDirectory macports-test-svn-wc $tempdir
737    removeDirectory macports-test-svn-repo $tempdir
738} -result {Subversion {SVN update --non-interactive WC}}
739
740
741testConstraint hasGit [expr {![catch {macports::findBinary git} git]}]
742
743test GetVCSUpdateCmd-git {
744    Tests GetVCSUpdateCmd on a valid Git repository
745} -constraints {
746    hasGit
747} -setup {
748    set repo [makeDirectory macports-test-git-repo $tempdir]
749    exec $git init $repo
750} -body {
751    string map [list $git GIT $repo REPO] [macports::GetVCSUpdateCmd $repo]
752} -cleanup {
753    removeDirectory macports-test-git-repo $tempdir
754} -result {Git {cd REPO && GIT pull --rebase || true}}
755
756
757testConstraint hasGitSvn [expr {
758    ![catch {macports::findBinary git} git] &&
759    [file readable [file join [exec $git --exec-path] git-svn]]
760}]
761
762test GetVCSUpdateCmd-gitsvn {
763    Tests GetVCSUpdateCmd on a valid git-svn repository
764} -constraints {
765    hasGitSvn
766} -setup {
767    set repo [makeDirectory macports-test-git-svn-repo $tempdir]
768    exec $git svn init http://localhost $repo
769} -body {
770    string map [list $git GIT $repo REPO] [macports::GetVCSUpdateCmd $repo]
771} -cleanup {
772    removeDirectory macports-test-git-svn-repo $tempdir
773} -result {git-svn {cd REPO && GIT svn rebase || true}}
774
775
776test GetVCSUpdateCmd-none {
777    Tests GetVCSUpdateCmd on directories that aren't recognized repositories
778} -setup {
779    set repo [makeDirectory macports-test-non-repo $tempdir]
780} -body {
781    macports::GetVCSUpdateCmd $repo
782} -cleanup {
783    removeDirectory macports-test-non-repo $tempdir
784} -result {}
785
786
787# test updatevcs
788# test mportsync
789# test mportsearch
790# test mportlookup
791# test mportlistall
792# test _mports_load_quickindex
793# test mports_generate_quickindex
794
795
796# test _mportkey
797# test mportdepends
798# test _mport_supports_archs
799# test _mport_archs
800# test _active_supports_archs
801# test _active_archs
802# test _explain_arch_mismatch
803# test _mport_has_deptypes
804# test _target_needs_deps
805# test _deptypes_for_target
806# test selfupdate
807# test upgrade
808# test _upgrade
809# test _upgrade_dependencies
810
811
812test mportselect {
813    Mport select unit test.
814} -setup {
815    set macports::prefix $pwd/prefix
816
817    file mkdir $macports::prefix/etc/select/group
818    set f1 [open $macports::prefix/etc/select/group/file1 w+]
819    set f2 [open $macports::prefix/etc/select/group/file2 w+]
820    set f3 [open $macports::prefix/srcs w+]
821    puts $f1 "srcs\n"
822    close $f1
823    close $f2
824    close $f3
825
826    set fd [open $macports::prefix/etc/select/group/base w+]
827    puts $fd "a\nb"
828    close $fd
829} -body {
830    if {[mportselect list group] ne {file1 file2}} {
831       return "FAIL: files not listed"
832    }
833    if {[mportselect set group file1] ne ""} {
834       reutrn "FAIL: cannot set links"
835    }
836    if {![file exists $macports::prefix/a]} {
837       return "FAIL: link not created"
838    }
839    if {[mportselect show group] ne "file1"} {
840       return "FAIL: file not selected"
841    }
842    return "Mport select successful."
843
844} -cleanup {
845    file delete -force $macports::prefix
846} -result "Mport select successful."
847
848
849test gettmpdir {
850    Get tmp dir unit test.
851} -body {
852    global env
853    set env(TMPDIR) temporal
854    if {[macports::gettmpdir] ne "temporal"} {
855       return "FAIL: set temp dir not detected"
856    }
857    unset env(TMPDIR)
858    if {[macports::gettmpdir] ne "/tmp"} {
859       return "FAIL: default value not set"
860    }
861    return "Get tmp dir successful."
862} -result "Get tmp dir successful."
863
864
865test arch_runnable {
866    Arch runnable unit test.
867} -body {
868    set macports::os_major 12
869    set macports::os_arch i386
870    set macports::os_platform darwin
871    if {[macports::arch_runnable ppc1] != no} {
872       return "FAIL: major:12 arch:i386 arch:ppc* not detected"
873    }
874    if {[macports::arch_runnable ppc64] != no} {
875       return "FAIL: major:12 arch:i386 arch:ppc64 not detected"
876    }
877    set macports::os_major 7
878    set macports::os_arch i386
879    set macports::os_platform darwin
880    if {[macports::arch_runnable x86_64] != no} {
881       return "FAIL: major:7 arch:i386 arch:x86_64 not detected"
882    }
883    set macports::os_major 12
884    set macports::os_arch i386
885    set macports::os_platform darwin
886    if {[macports::arch_runnable x86_64] != yes} {
887       return "FAIL: major:12 arch:i386 arch:x86_64 not detected"
888    }
889    return "Arch runnable successful."
890} -result "Arch runnable successful."
891
892
893# test revupgrade
894# test revupgrade_scanandrebuild
895
896
897test path_is_in_prefix {
898    Path is in prefix unit test.
899} -body {
900    set macports::applications_dir appdir
901    if {[macports::path_is_in_prefix appdir/test/port] != yes} {
902       return "FAIL: application dir not detected"
903    }
904    set macports::prefix prefix
905    if {[macports::path_is_in_prefix prefix/test/port] != yes} {
906       return "FAIL: prefix not detected"
907    }
908    if {[macports::path_is_in_prefix test/port] != no} {
909       return "FAIL: no prefix detected"
910    }
911    return "Path prefix successful."
912} -result "Path prefix successful."
913
914
915test revupgrade_handle_special_paths {
916    Revupgrade handle special paths unit test.
917} -body {
918    set res [macports::revupgrade_handle_special_paths fname test_path]
919    if {$res ne "test_path"} {
920       return "FAIL: wrong path"
921    }
922    set res [macports::revupgrade_handle_special_paths fname @loader_path/test_load]
923    if {$res ne "./test_load"} {
924       return "FAIL: wrong load path"
925    }
926    return "Revupgrade handle special path successful."
927} -result "Revupgrade handle special path successful."
928
929
930# test revupgrade_buildgraph
931
932
933test get_pingtime {
934    Get ping time unit test.
935} -setup {
936    set time [expr [clock seconds] - 86300]
937    set macports::ping_cache(macports.org) [list MacPorts $time]
938    set macports::host_blacklisted(macports_blacklist) [list black $time]
939    set macports::host_preferred(macports_pref) [list pref $time]
940
941} -body {
942    if {[macports::get_pingtime macports.org] ne "MacPorts"} {
943       return "FAIL: wrong ping time"
944    }
945    if {[macports::get_pingtime macports_blacklist] != -1} {
946       return "FAIL: wrong time for blacklisted host"
947    }
948    if {[macports::get_pingtime macports_pref] != 1} {
949       return "FAIL: wrong time for preferred host"
950    }
951    return "Get ping time successful."
952} -result "Get ping time successful."
953
954
955test set_pingtime {
956    Set ping time unit test.
957} -body {
958    set macports::ping_cache(macports) {}
959    if {[lindex [macports::set_pingtime macports 007] 0] != 007} {
960       return "FAIL: ping time not set"
961    }
962    return "Set ping time successful."
963} -result "Set ping time successful."
964
965
966test get_archive_sites_conf_values {
967    Get archive sites conf values unit test.
968} -setup {
969    file mkdir $pwd/archive_sites
970    set fd [open $pwd/archive_sites/archive_sites.conf w+]
971    puts $fd "name fondu"
972    puts $fd "urls macports.org"
973    puts $fd "type tgz"
974    close $fd
975
976    set macports::autoconf::macports_conf_path $pwd/archive_sites
977    unset -nocomplain macports::archive_sites_conf_values
978} -body {
979    set res [macports::get_archive_sites_conf_values]
980    puts $res
981    if {[lindex [split $res " "] 1] ne "macports.org:nosubdir"} {
982       return "FAIL: name not set"
983    }
984    if {[lindex [split $res " "] 3] ne "tgz"} {
985       return "FAIL: wrong type set"
986    }
987
988    set macports::archive_sites_conf_values {a b c}
989    if {[macports::get_archive_sites_conf_values] ne {a b c}} {
990       return "FAIL: wrong  result for bad conf file"
991    }
992    return "Get archive sites conf values successful."
993
994} -cleanup {
995    file delete -force $pwd/archive_sites
996} -result "Get archive sites conf values successful."
997
998
999set shellescapeTests [list \
1000    "using \\backslashes" \
1001    " spaces " \
1002    "and        tabs" \
1003    "quotes need to be \"supported\", too" \
1004    "… and not only 'double-quotes'" \
1005    "other meta chars such as \$dollar," \
1006    "!bang, ;semicolon, :colon," \
1007    "\$(subshells) and similar must be kept" \
1008    ">redirects <& must be ignored as well as ampersands &"]
1009test shellescaping {
1010    Check whether shell escaping using macports::shellescape works correctly when passed to Pextlib's system extension.
1011} -setup {
1012    set outputfile "shellescapetestoutput.txt"
1013    makeFile "" $outputfile
1014
1015} -body {
1016    set first "yes"
1017    foreach test $shellescapeTests {
1018        if {$first eq "yes"} {
1019            system "echo [macports::shellescape $test]  >$outputfile"
1020            set first "no"
1021        } else {
1022            system "echo [macports::shellescape $test] >>$outputfile"
1023        }
1024    }
1025
1026    set fd [open $outputfile r]
1027    set output [read -nonewline $fd]
1028    close $fd
1029    return $output
1030} -cleanup {
1031    removeFile $outputfile
1032} -result [join $shellescapeTests "\n"]
1033
1034cleanupTests
Note: See TracBrowser for help on using the repository browser.