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

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

Run tests in non-interactive mode

Tests need to be non-interactive. Ports requiring user input should be flagged
with the userInteraction constraint.

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