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