summaryrefslogtreecommitdiffstats
path: root/tests/pkg.test
blob: 0a7833f7ac5e61423d355245e65884e51adf6645 (plain)
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
# Commands covered:  pkg
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 1995-1996 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
# RCS: @(#) $Id: pkg.test,v 1.9.12.2 2005/11/18 19:27:19 dgp Exp $

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2
    namespace import -force ::tcltest::*
}

# Do all this in a slave interp to avoid garbaging the
# package list
set i [interp create]
interp eval $i [list set argv $argv]
interp eval $i [list package require tcltest 2]
interp eval $i [list namespace import -force ::tcltest::*]
interp eval $i {

eval package forget [package names]
set oldPkgUnknown [package unknown]
package unknown {}
set oldPath $auto_path
set auto_path ""

test pkg-1.1 {Tcl_PkgProvide procedure} {
    package forget t
    package provide t 2.3
} {}
test pkg-1.2 {Tcl_PkgProvide procedure} {
    package forget t
    package provide t 2.3
    list [catch {package provide t 2.2} msg] $msg
} {1 {conflicting versions provided for package "t": 2.3, then 2.2}}
test pkg-1.3 {Tcl_PkgProvide procedure} {
    package forget t
    package provide t 2.3
    list [catch {package provide t 2.4} msg] $msg
} {1 {conflicting versions provided for package "t": 2.3, then 2.4}}
test pkg-1.4 {Tcl_PkgProvide procedure} {
    package forget t
    package provide t 2.3
    list [catch {package provide t 3.3} msg] $msg
} {1 {conflicting versions provided for package "t": 2.3, then 3.3}}
test pkg-1.5 {Tcl_PkgProvide procedure} {
    package forget t
    package provide t 2.3
    package provide t 2.3
} {}

test pkg-2.1 {Tcl_PkgRequire procedure, picking best version} {
    package forget t
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i; package provide t $i"
    }
    set x xxx
    package require t
    set x
} {3.4}
test pkg-2.2 {Tcl_PkgRequire procedure, picking best version} {
    package forget t
    foreach i {1.4 3.4 2.3 2.4 2.2 3.5 3.2} {
	package ifneeded t $i "set x $i; package provide t $i"
    }
    set x xxx
    package require t
    set x
} {3.5}
test pkg-2.3 {Tcl_PkgRequire procedure, picking best version} {
    package forget t
    foreach i {3.5 2.1 2.3} {
	package ifneeded t $i "set x $i; package provide t $i"
    }
    set x xxx
    package require t 2.2
    set x
} {2.3}
test pkg-2.4 {Tcl_PkgRequire procedure, picking best version} {
    package forget t
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i; package provide t $i"
    }
    set x xxx
    package require -exact t 2.3
    set x
} {2.3}
test pkg-2.5 {Tcl_PkgRequire procedure, picking best version} {
    package forget t
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i; package provide t $i"
    }
    set x xxx
    package require t 2.1
    set x
} {2.4}
test pkg-2.6 {Tcl_PkgRequire procedure, can't find suitable version} {
    package forget t
    package unknown {}
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i"
    }
    list [catch {package require t 2.5} msg] $msg
} {1 {can't find package t 2.5}}
test pkg-2.7 {Tcl_PkgRequire procedure, can't find suitable version} {
    package forget t
    package unknown {}
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i"
    }
    list [catch {package require t 4.1} msg] $msg
} {1 {can't find package t 4.1}}
test pkg-2.8 {Tcl_PkgRequire procedure, can't find suitable version} {
    package forget t
    package unknown {}
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i"
    }
    list [catch {package require -exact t 1.3} msg] $msg
} {1 {can't find package t 1.3}}
test pkg-2.9 {Tcl_PkgRequire procedure, can't find suitable version} {
    package forget t
    package unknown {}
    list [catch {package require t} msg] $msg
} {1 {can't find package t}}
test pkg-2.10 {Tcl_PkgRequire procedure, error in ifneeded script} -body {
    package forget t
    package ifneeded t 2.1 {package provide t 2.1; error "ifneeded test"}
    list [catch {package require t 2.1} msg] $msg $errorInfo
} -match glob -result {1 {ifneeded test} {ifneeded test
    while executing
"error "ifneeded test""
    ("package ifneeded*" script)
    invoked from within
"package require t 2.1"}}
test pkg-2.11 {Tcl_PkgRequire procedure, ifneeded script doesn't provide package} -body {
    package forget t
    package ifneeded t 2.1 "set x invoked"
    set x xxx
    list [catch {package require t 2.1} msg] $msg $x
} -match glob -result {1 * invoked}
test pkg-2.12 {Tcl_PkgRequire procedure, self-deleting script} {
    package forget t
    package ifneeded t 1.2 "package forget t; set x 1.2; package provide t 1.2"
    set x xxx
    package require t 1.2
    set x
} {1.2}
test pkg-2.13 {Tcl_PkgRequire procedure, "package unknown" support} {
    proc pkgUnknown args {
	global x
	set x $args
	package provide [lindex $args 0] [lindex $args 1]
    }
    package forget t
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i"
    }
    package unknown pkgUnknown
    set x xxx
    package require -exact t 1.5
    package unknown {}
    set x
} {t 1.5 -exact}
test pkg-2.14 {Tcl_PkgRequire procedure, "package unknown" support} {
    proc pkgUnknown args {
	package ifneeded t 1.2 "set x loaded; package provide t 1.2"
    }
    package forget t
    package unknown pkgUnknown
    set x xxx
    set result [list [package require t] $x]
    package unknown {}
    set result
} {1.2 loaded}
test pkg-2.15 {Tcl_PkgRequire procedure, "package unknown" support} {
    proc pkgUnknown args {
	global x
	set x $args
	package provide [lindex $args 0] 2.0
    }
    package forget {a b}
    package unknown pkgUnknown
    set x xxx
    package require {a b}
    package unknown {}
    set x
} {{a b} {}}
test pkg-2.16 {Tcl_PkgRequire procedure, "package unknown" error} {
    proc pkgUnknown args {
	error "testing package unknown"
    }
    package forget t 
    package unknown pkgUnknown
    set result [list [catch {package require t} msg] $msg $errorInfo]
    package unknown {}
    set result
} {1 {testing package unknown} {testing package unknown
    while executing
"error "testing package unknown""
    (procedure "pkgUnknown" line 2)
    invoked from within
"pkgUnknown t {}"
    ("package unknown" script)
    invoked from within
"package require t"}}
test pkg-2.17 {Tcl_PkgRequire procedure, "package unknown" doesn't load package} {
    proc pkgUnknown args {
	global x
	set x $args
    }
    package forget t
    foreach i {1.4 3.4 2.3 2.4 2.2} {
	package ifneeded t $i "set x $i"
    }
    package unknown pkgUnknown
    set x xxx
    set result [list [catch {package require -exact t 1.5} msg] $msg $x]
    package unknown {}
    set result
} {1 {can't find package t 1.5} {t 1.5 -exact}}
test pkg-2.18 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    package require t
} {2.3}
test pkg-2.19 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    package require t 2.1
} {2.3}
test pkg-2.20 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    package require t 2.3
} {2.3}
test pkg-2.21 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    list [catch {package require t 2.4} msg] $msg
} {1 {version conflict for package "t": have 2.3, need 2.4}}
test pkg-2.22 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    list [catch {package require t 1.2} msg] $msg
} {1 {version conflict for package "t": have 2.3, need 1.2}}
test pkg-2.23 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    package require -exact t 2.3
} {2.3}
test pkg-2.24 {Tcl_PkgRequire procedure, version checks} {
    package forget t
    package provide t 2.3
    list [catch {package require -exact t 2.2} msg] $msg
} {1 {version conflict for package "t": have 2.3, need 2.2}}
test pkg-2.25 {Tcl_PkgRequire procedure, error in ifneeded script} -body {
    package forget t
    package ifneeded t 2.1 {package provide t 2.1; error "ifneeded test" EI}
    list [catch {package require t 2.1} msg] $msg $errorInfo
} -match glob -result {1 {ifneeded test} {EI
    ("package ifneeded*" script)
    invoked from within
"package require t 2.1"}} -constraints knownBug
test pkg-2.26 {Tcl_PkgRequire procedure, error in ifneeded script} -body {
    package forget t
    package ifneeded t 2.1 {package provide t 2.1; foreach x 1 {error "ifneeded test" EI}}
    list [catch {package require t 2.1} msg] $msg $errorInfo
} -match glob -result {1 {ifneeded test} {EI
    ("foreach" body line 1)
    invoked from within
"foreach x 1 {error "ifneeded test" EI}"
    ("package ifneeded*" script)
    invoked from within
"package require t 2.1"}}
test pkg-2.27 {Tcl_PkgRequire: circular dependency} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {package require foo 1}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob -result {circular package dependency:*}
test pkg-2.28 {Tcl_PkgRequire: circular dependency} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {package require foo 2}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob -result {circular package dependency:*}
test pkg-2.29 {Tcl_PkgRequire: circular dependency} -setup {
    package forget foo
    package forget bar
} -body {
    package ifneeded foo 1 {package require bar 1; package provide foo 1}
    package ifneeded bar 1 {package require foo 1; package provide bar 1}
    package require foo 1
} -cleanup {
    package forget foo
    package forget bar
} -returnCodes error -match glob -result {circular package dependency:*}
test pkg-2.30 {Tcl_PkgRequire: circular dependency} -setup {
    package forget foo
    package forget bar
} -body {
    package ifneeded foo 1 {package require bar 1; package provide foo 1}
    package ifneeded foo 2 {package provide foo 2}
    package ifneeded bar 1 {package require foo 2; package provide bar 1}
    package require foo 1
} -cleanup {
    package forget foo
    package forget bar
} -returnCodes error -match glob -result {circular package dependency:*}
test pkg-2.31 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {package provide foo 1; error foo}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob -result foo
test pkg-2.32 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {package provide foo 1; error foo}
    catch {package require foo 1}
    package provide foo
} -cleanup {
    package forget foo
} -result {}
test pkg-2.33 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {package provide foo 2}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob -result {attempt to provide package * failed:*}
test pkg-2.34 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {package provide foo 1.1}
    package require foo 1
} -cleanup {
    package forget foo
} -match glob -result 1.1 -errorOutput {attempt to provide package * failed:*}
test pkg-2.34.1 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1.1 {package provide foo 1}
    package require foo 1
} -cleanup {
    package forget foo
} -match glob -result 1 -errorOutput {attempt to provide package * failed:*}
test pkg-2.34.2 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1.1 {package provide foo 1}
    package require foo 1.1
} -cleanup {
    package forget foo
} -returnCodes error -match glob -result {attempt to provide package * failed:*}
test pkg-2.35 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob -result {attempt to provide package * failed:*}
test pkg-2.35 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {break}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob \
-result {attempt to provide package * failed: bad return code:*}
test pkg-2.36 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {continue}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob \
-result {attempt to provide package * failed: bad return code:*}
test pkg-2.37 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {return}
    package require foo 1
} -cleanup {
    package forget foo
} -returnCodes error -match glob \
-result {attempt to provide package * failed: bad return code:*}
test pkg-2.38 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
} -body {
    package ifneeded foo 1 {proc x {} {return -code 10}; x}
    package require foo 1
} -cleanup {
    rename x {}
    package forget foo
} -returnCodes error -match glob \
-result {attempt to provide package * failed: bad return code:*}
test pkg-2.39 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
    set saveUnknown [package unknown]
    package unknown {package provide foo 2 ;#}
} -body {
    package require foo 1
} -cleanup {
    package forget foo
    package unknown $saveUnknown
} -returnCodes error -match glob -result *
test pkg-2.40 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
    set saveUnknown [package unknown]
    package unknown {break ;#}
} -body {
    package require foo 1
} -cleanup {
    package forget foo
    package unknown $saveUnknown
} -returnCodes error -match glob -result {bad return code:*}
test pkg-2.41 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
    set saveUnknown [package unknown]
    package unknown {continue ;#}
} -body {
    package require foo 1
} -cleanup {
    package forget foo
    package unknown $saveUnknown
} -returnCodes error -match glob -result {bad return code:*}
test pkg-2.42 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
    set saveUnknown [package unknown]
    package unknown {return ;#}
} -body {
    package require foo 1
} -cleanup {
    package forget foo
    package unknown $saveUnknown
} -returnCodes error -match glob -result {bad return code:*}
test pkg-2.43 {Tcl_PkgRequire: consistent return values (1162286)} -setup {
    package forget foo
    set saveUnknown [package unknown]
    proc x args {return -code 10}
    package unknown x
} -body {
    package require foo 1
} -cleanup {
    rename x {}
    package forget foo
    package unknown $saveUnknown
} -returnCodes error -match glob -result {bad return code:*}

test pkg-3.1 {Tcl_PackageCmd procedure} {
    list [catch {package} msg] $msg
} {1 {wrong # args: should be "package option ?arg arg ...?"}}
test pkg-3.2 {Tcl_PackageCmd procedure, "forget" option} {
    foreach i [package names] {
	package forget $i
    }
    package names
} {}
test pkg-3.3 {Tcl_PackageCmd procedure, "forget" option} {
    foreach i [package names] {
	package forget $i
    }
    package forget foo
} {}
test pkg-3.4 {Tcl_PackageCmd procedure, "forget" option} {
    foreach i [package names] {
	package forget $i
    }
    package ifneeded t 1.1 {first script}
    package ifneeded t 2.3 {second script}
    package ifneeded x 1.4 {x's script}
    set result {}
    lappend result [lsort [package names]] [package versions t]
    package forget t
    lappend result [lsort [package names]] [package versions t]
} {{t x} {1.1 2.3} x {}}
test pkg-3.5 {Tcl_PackageCmd procedure, "forget" option} {
    foreach i [package names] {
	package forget $i
    }
    package ifneeded a 1.1 {first script}
    package ifneeded b 2.3 {second script}
    package ifneeded c 1.4 {third script}
    package forget
    set result [list [lsort [package names]]]
    package forget a c
    lappend result [lsort [package names]]
} {{a b c} b}
test pkg-3.5.1 {Tcl_PackageCmd procedure, "forget" option} {
    # Test for Bug 415273
    package ifneeded a 1 "I should have been forgotten"
    package forget no-such-package a
    set x [package ifneeded a 1]
    package forget a
    set x
} {}
test pkg-3.6 {Tcl_PackageCmd procedure, "ifneeded" option} {
    list [catch {package ifneeded a} msg] $msg
} {1 {wrong # args: should be "package ifneeded package version ?script?"}}
test pkg-3.7 {Tcl_PackageCmd procedure, "ifneeded" option} {
    list [catch {package ifneeded a b c d} msg] $msg
} {1 {wrong # args: should be "package ifneeded package version ?script?"}}
test pkg-3.8 {Tcl_PackageCmd procedure, "ifneeded" option} {
    list [catch {package ifneeded t xyz} msg] $msg
} {1 {expected version number but got "xyz"}}
test pkg-3.9 {Tcl_PackageCmd procedure, "ifneeded" option} {
    foreach i [package names] {
	package forget $i
    }
    list [package ifneeded foo 1.1] [package names]
} {{} {}}
test pkg-3.10 {Tcl_PackageCmd procedure, "ifneeded" option} {
    package forget t
    package ifneeded t 1.4 "script for t 1.4"
    list [package names] [package ifneeded t 1.4] [package versions t]
} {t {script for t 1.4} 1.4}
test pkg-3.11 {Tcl_PackageCmd procedure, "ifneeded" option} {
    package forget t
    package ifneeded t 1.4 "script for t 1.4"
    list [package ifneeded t 1.5] [package names] [package versions t]
} {{} t 1.4}
test pkg-3.12 {Tcl_PackageCmd procedure, "ifneeded" option} {
    package forget t
    package ifneeded t 1.4 "script for t 1.4"
    package ifneeded t 1.4 "second script for t 1.4"
    list [package ifneeded t 1.4] [package names] [package versions t]
} {{second script for t 1.4} t 1.4}
test pkg-3.13 {Tcl_PackageCmd procedure, "ifneeded" option} {
    package forget t
    package ifneeded t 1.4 "script for t 1.4"
    package ifneeded t 1.2 "second script"
    package ifneeded t 3.1 "last script"
    list [package ifneeded t 1.2] [package versions t]
} {{second script} {1.4 1.2 3.1}}
test pkg-3.14 {Tcl_PackageCmd procedure, "names" option} {
    list [catch {package names a} msg] $msg
} {1 {wrong # args: should be "package names"}}
test pkg-3.15 {Tcl_PackageCmd procedure, "names" option} {
    foreach i [package names] {
	package forget $i
    }
    package names
} {}
test pkg-3.16 {Tcl_PackageCmd procedure, "names" option} {
    foreach i [package names] {
	package forget $i
    }
    package ifneeded x 1.2 {dummy}
    package provide x 1.3
    package provide y 2.4
    catch {package require z 47.16}
    lsort [package names]
} {x y}
test pkg-3.17 {Tcl_PackageCmd procedure, "provide" option} {
    list [catch {package provide} msg] $msg
} {1 {wrong # args: should be "package provide package ?version?"}}
test pkg-3.18 {Tcl_PackageCmd procedure, "provide" option} {
    list [catch {package provide a b c} msg] $msg
} {1 {wrong # args: should be "package provide package ?version?"}}
test pkg-3.19 {Tcl_PackageCmd procedure, "provide" option} {
    package forget t
    package provide t
} {}
test pkg-3.20 {Tcl_PackageCmd procedure, "provide" option} {
    package forget t
    package provide t 2.3
    package provide t
} {2.3}
test pkg-3.21 {Tcl_PackageCmd procedure, "provide" option} {
    package forget t
    list [catch {package provide t a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-3.22 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require} msg] $msg
} {1 {wrong # args: should be "package require ?-exact? package ?version?"}}
test pkg-3.23 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require a b c} msg] $msg
} {1 {wrong # args: should be "package require ?-exact? package ?version?"}}
test pkg-3.24 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require -exact a b c} msg] $msg
} {1 {wrong # args: should be "package require ?-exact? package ?version?"}}
test pkg-3.25 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require -bs a b} msg] $msg
} {1 {wrong # args: should be "package require ?-exact? package ?version?"}}
test pkg-3.26 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require x a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-3.27 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require -exact x a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-3.28 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require -exact x} msg] $msg
} {1 {wrong # args: should be "package require ?-exact? package ?version?"}}
test pkg-3.29 {Tcl_PackageCmd procedure, "require" option} {
    list [catch {package require -exact} msg] $msg
} {1 {wrong # args: should be "package require ?-exact? package ?version?"}}
test pkg-3.30 {Tcl_PackageCmd procedure, "require" option} {
    package forget t
    package provide t 2.3
    package require t 2.1
} {2.3}
test pkg-3.31 {Tcl_PackageCmd procedure, "require" option} {
    package forget t
    list [catch {package require t} msg] $msg
} {1 {can't find package t}}
test pkg-3.32 {Tcl_PackageCmd procedure, "require" option} {
    package forget t
    package ifneeded t 2.3 "error {synthetic error}"
    list [catch {package require t 2.3} msg] $msg
} {1 {synthetic error}}
test pkg-3.33 {Tcl_PackageCmd procedure, "unknown" option} {
    list [catch {package unknown a b} msg] $msg
} {1 {wrong # args: should be "package unknown ?command?"}}
test pkg-3.34 {Tcl_PackageCmd procedure, "unknown" option} {
    package unknown "test script"
    package unknown
} {test script}
test pkg-3.35 {Tcl_PackageCmd procedure, "unknown" option} {
    package unknown "test script"
    package unknown {}
    package unknown
} {}
test pkg-3.36 {Tcl_PackageCmd procedure, "vcompare" option} {
    list [catch {package vcompare a} msg] $msg
} {1 {wrong # args: should be "package vcompare version1 version2"}}
test pkg-3.37 {Tcl_PackageCmd procedure, "vcompare" option} {
    list [catch {package vcompare a b c} msg] $msg
} {1 {wrong # args: should be "package vcompare version1 version2"}}
test pkg-3.38 {Tcl_PackageCmd procedure, "vcompare" option} {
    list [catch {package vcompare x.y 3.4} msg] $msg
} {1 {expected version number but got "x.y"}}
test pkg-3.39 {Tcl_PackageCmd procedure, "vcompare" option} {
    list [catch {package vcompare 2.1 a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-3.40 {Tcl_PackageCmd procedure, "vcompare" option} {
    package vc 2.1 2.3
} {-1}
test pkg-3.41 {Tcl_PackageCmd procedure, "vcompare" option} {
    package vc 2.2.4 2.2.4
} {0}
test pkg-3.42 {Tcl_PackageCmd procedure, "versions" option} {
    list [catch {package versions} msg] $msg
} {1 {wrong # args: should be "package versions package"}}
test pkg-3.43 {Tcl_PackageCmd procedure, "versions" option} {
    list [catch {package versions a b} msg] $msg
} {1 {wrong # args: should be "package versions package"}}
test pkg-3.44 {Tcl_PackageCmd procedure, "versions" option} {
    package forget t
    package versions t
} {}
test pkg-3.45 {Tcl_PackageCmd procedure, "versions" option} {
    package forget t
    package provide t 2.3
    package versions t
} {}
test pkg-3.46 {Tcl_PackageCmd procedure, "versions" option} {
    package forget t
    package ifneeded t 2.3 x
    package ifneeded t 2.4 y
    package versions t
} {2.3 2.4}
test pkg-3.47 {Tcl_PackageCmd procedure, "vsatisfies" option} {
    list [catch {package vsatisfies a} msg] $msg
} {1 {wrong # args: should be "package vsatisfies version1 version2"}}
test pkg-3.48 {Tcl_PackageCmd procedure, "vsatisfies" option} {
    list [catch {package vsatisfies a b c} msg] $msg
} {1 {wrong # args: should be "package vsatisfies version1 version2"}}
test pkg-3.49 {Tcl_PackageCmd procedure, "vsatisfies" option} {
    list [catch {package vsatisfies x.y 3.4} msg] $msg
} {1 {expected version number but got "x.y"}}
test pkg-3.50 {Tcl_PackageCmd procedure, "vsatisfies" option} {
    list [catch {package vcompare 2.1 a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-3.51 {Tcl_PackageCmd procedure, "vsatisfies" option} {
    package vs 2.3 2.1
} {1}
test pkg-3.52 {Tcl_PackageCmd procedure, "vsatisfies" option} {
    package vs 2.3 1.2
} {0}
test pkg-3.53 {Tcl_PackageCmd procedure, "versions" option} {
    list [catch {package foo} msg] $msg
} {1 {bad option "foo": must be forget, ifneeded, names, present, provide, require, unknown, vcompare, versions, or vsatisfies}}

# No tests for FindPackage;  can't think up anything detectable
# errors.

test pkg-4.1 {TclFreePackageInfo procedure} {
    interp create foo
    foo eval {
	package ifneeded t 2.3 x
	package ifneeded t 2.4 y
	package ifneeded x 3.1 z
	package provide q 4.3
	package unknown "will this get freed?"
    }
    interp delete foo
} {}
test pkg-4.2 {TclFreePackageInfo procedure} -body {
    interp create foo
    foo eval {
	package ifneeded t 2.3 x
	package ifneeded t 2.4 y
	package ifneeded x 3.1 z
	package provide q 4.3
    }
    foo alias z kill
    proc kill {} {
	interp delete foo
    }
    foo eval package require x 3.1
} -returnCodes error -match glob -result *

test pkg-5.1 {CheckVersion procedure} {
    list [catch {package vcompare 1 2.1} msg] $msg
} {0 -1}
test pkg-5.2 {CheckVersion procedure} {
    list [catch {package vcompare .1 2.1} msg] $msg
} {1 {expected version number but got ".1"}}
test pkg-5.3 {CheckVersion procedure} {
    list [catch {package vcompare 111.2a.3 2.1} msg] $msg
} {1 {expected version number but got "111.2a.3"}}
test pkg-5.4 {CheckVersion procedure} {
    list [catch {package vcompare 1.2.3. 2.1} msg] $msg
} {1 {expected version number but got "1.2.3."}}
test pkg-5.5 {CheckVersion procedure} {
    list [catch {package vcompare 1.2..3 2.1} msg] $msg
} {1 {expected version number but got "1.2..3"}}

test pkg-6.1 {ComparePkgVersions procedure} {
    package vcompare 1.23 1.22
} {1}
test pkg-6.2 {ComparePkgVersions procedure} {
    package vcompare 1.22.1.2.3 1.22.1.2.3
} {0}
test pkg-6.3 {ComparePkgVersions procedure} {
    package vcompare 1.21 1.22
} {-1}
test pkg-6.4 {ComparePkgVersions procedure} {
    package vcompare 1.21 1.21.2
} {-1}
test pkg-6.5 {ComparePkgVersions procedure} {
    package vcompare 1.21.1 1.21
} {1}
test pkg-6.6 {ComparePkgVersions procedure} {
    package vsatisfies 1.21.1 1.21
} {1}
test pkg-6.7 {ComparePkgVersions procedure} {
    package vsatisfies 2.22.3 1.21
} {0}
test pkg-6.8 {ComparePkgVersions procedure} {
    package vsatisfies 1 1
} {1}
test pkg-6.9 {ComparePkgVersions procedure} {
    package vsatisfies 2 1
} {0}

test pkg-7.1 {Tcl_PkgPresent procedure, any version} {
    package forget t
    package provide t 2.4
    package present t
} {2.4}
test pkg-7.2 {Tcl_PkgPresent procedure, correct version} {
    package forget t
    package provide t 2.4
    package present t 2.4
} {2.4}
test pkg-7.3 {Tcl_PkgPresent procedure, satisfying version} {
    package forget t
    package provide t 2.4
    package present t 2.0
} {2.4}
test pkg-7.4 {Tcl_PkgPresent procedure, not satisfying version} {
    package forget t
    package provide t 2.4
    list [catch {package present t 2.6} msg] $msg
} {1 {version conflict for package "t": have 2.4, need 2.6}}
test pkg-7.5 {Tcl_PkgPresent procedure, not satisfying version} {
    package forget t
    package provide t 2.4
    list [catch {package present t 1.0} msg] $msg
} {1 {version conflict for package "t": have 2.4, need 1.0}}
test pkg-7.6 {Tcl_PkgPresent procedure, exact version} {
    package forget t
    package provide t 2.4
    package present -exact t 2.4
} {2.4}
test pkg-7.7 {Tcl_PkgPresent procedure, not exact version} {
    package forget t
    package provide t 2.4
    list [catch {package present -exact t 2.3} msg] $msg
} {1 {version conflict for package "t": have 2.4, need 2.3}}
test pkg-7.8 {Tcl_PkgPresent procedure, unknown package} {
    package forget t
    list [catch {package present t} msg] $msg
} {1 {package t is not present}}
test pkg-7.9 {Tcl_PkgPresent procedure, unknown package} {
    package forget t
    list [catch {package present t 2.4} msg] $msg
} {1 {package t 2.4 is not present}}
test pkg-7.10 {Tcl_PkgPresent procedure, unknown package} {
    package forget t
    list [catch {package present -exact t 2.4} msg] $msg
} {1 {package t 2.4 is not present}}
test pkg-7.11 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present} msg] $msg
} {1 {wrong # args: should be "package present ?-exact? package ?version?"}}
test pkg-7.12 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present a b c} msg] $msg
} {1 {wrong # args: should be "package present ?-exact? package ?version?"}}
test pkg-7.13 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present -exact a b c} msg] $msg
} {1 {wrong # args: should be "package present ?-exact? package ?version?"}}
test pkg-7.14 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present -bs a b} msg] $msg
} {1 {wrong # args: should be "package present ?-exact? package ?version?"}}
test pkg-7.15 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present x a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-7.16 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present -exact x a.b} msg] $msg
} {1 {expected version number but got "a.b"}}
test pkg-7.17 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present -exact x} msg] $msg
} {1 {wrong # args: should be "package present ?-exact? package ?version?"}}
test pkg-7.18 {Tcl_PackageCmd procedure, "present" option} {
    list [catch {package present -exact} msg] $msg
} {1 {wrong # args: should be "package present ?-exact? package ?version?"}}

set auto_path $oldPath
package unknown $oldPkgUnknown
concat

cleanupTests
}

# cleanup
interp delete $i
::tcltest::cleanupTests
return