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
|
#
# chmod.test
#
# Tests for the chmod, chown and chgrp commands.
#---------------------------------------------------------------------------
# Copyright 1992-1999 Karl Lehenbauer and Mark Diekhans.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted, provided
# that the above copyright notice appear in all copies. Karl Lehenbauer and
# Mark Diekhans make no representations about the suitability of this
# software for any purpose. It is provided "as is" without express or
# implied warranty.
#------------------------------------------------------------------------------
# $Id: chmod.test,v 1.3 2002/04/04 06:10:30 hobbs Exp $
#------------------------------------------------------------------------------
#
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest
namespace import ::tcltest::*
}
if {[cequal [info procs Test] {}]} {
source [file join [file dirname [info script]] testlib.tcl]
}
if [cequal $tcl_platform(platform) windows] {
echo " * The chmod, chown and chgrp commands have not been ported to Win32"
return
}
#-----------------------------------------------------------------------------
# This routine to the the mode of a file. It is returned formated in octal.
proc GetMode {filename} {
file stat $filename stat
return [format "%o" [expr {$stat(mode) & 07777}]]
}
#-----------------------------------------------------------------------------
# Certain Unix systems don't handle chmod the same. This routine test if the
# system chmod produces the expected results.
# o mode - symbolic mode to set the file to.
# o args - list of valid expected result from ls.
#
proc CheckChmod {mode args} {
global chmodTestsSkipped
set stat 0
if {[catch {
chmod 000 CHECK.TMP
exec chmod $mode CHECK.TMP
set sysMode [lindex [exec ls -l CHECK.TMP] 0]
}] == 0} {
if {[lsearch -exact $args $sysMode] >= 0} {
set stat 1
}
}
if !$stat {
incr chmodTestsSkipped
}
return $stat
}
global chmodTestsSkipped
set chmodTestsSkipped 0
#-----------------------------------------------------------------------------
# Procedure to return the uid of a file.
proc GetUID {file} {
file stat $file stat
return $stat(uid)
}
#-----------------------------------------------------------------------------
# Procedure to return the gid of a file.
proc GetGID {file} {
file stat $file stat
return $stat(gid)
}
#-----------------------------------------------------------------------------
# Procedure to return the uid and gid of a file.
proc GetUIDGID {file} {
file stat $file stat
return [list $stat(uid) $stat(gid)]
}
#-----------------------------------------------------------------------------
# If a user does not have a group name assigned, then some tests will not work,
# just blow off the tests and let the user make things right.
if {[catch {id group}] != 0} {
echo "User '[id user]' does not have group name. Chmod tests skipped"
return
}
#-----------------------------------------------------------------------------
# Purge existing test files and recreate them.
#
proc SetUpTestFiles {} {
foreach f {CHECK.TMP CHMOD.TMP CHMOD2.TMP} {
catch {
chmod a+w $f
file delete $f
}
close [open $f w]
}
}
SetUpTestFiles
# Set the umask so that no bits are masked. Some system chmods use umask
# if u, g, o or a are not specified in a symbolic chmod.
umask 000
test chmod-1.1 {chmod absolute mode tests} {
chmod 0000 CHMOD.TMP
chmod 0101 CHMOD.TMP
GetMode CHMOD.TMP
} {101}
test chmod-1.2 {chmod absolute mode tests} {
chmod 0000 CHMOD.TMP
chmod 0010 CHMOD.TMP
GetMode CHMOD.TMP
} {10}
test chmod-1.3 {chmod absolute mode tests} {
chmod 0000 CHMOD.TMP
chmod 0777 CHMOD.TMP
GetMode CHMOD.TMP
} {777}
test chmod-1.4 {chmod absolute mode tests} {
chmod 0000 CHMOD.TMP
chmod 0666 CHMOD.TMP
GetMode CHMOD.TMP
} {666}
test chmod-1.5 {chmod absolute mode tests} {
chmod 0000 CHMOD.TMP
chmod 0705 CHMOD.TMP
GetMode CHMOD.TMP
} {705}
test chmod-1.7 {chmod absolute mode tests} {
chmod 0000 CHMOD.TMP
chmod 04111 CHMOD.TMP
GetMode CHMOD.TMP
} {4111}
test chmod-1.9 {chmod absolute mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 0000 $fh
chmod -fileid 0101 $fh
close $fh
GetMode CHMOD.TMP
} {101}
test chmod-1.10 {chmod absolute mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 0000 $fh
chmod -fileid 0010 $fh
close $fh
GetMode CHMOD.TMP
} {10}
test chmod-1.11 {chmod absolute mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 0000 $fh
chmod -fileid 0777 $fh
close $fh
GetMode CHMOD.TMP
} {777}
test chmod-1.12 {chmod absolute mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 0000 $fh
chmod -fileid 0666 $fh
close $fh
GetMode CHMOD.TMP
} {666}
test chmod-1.13 {chmod absolute mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 0000 $fh
chmod -fileid 0705 $fh
close $fh
GetMode CHMOD.TMP
} {705}
test chmod-1.14 {chmod absolute mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 0000 $fh
chmod -fileid 04111 $fh
close $fh
GetMode CHMOD.TMP
} {4111}
test chmod-2.1 {chmod absolute integer mode tests} {
chmod 0 {CHMOD.TMP CHMOD2.TMP}
chmod 65 {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {101 101}
test chmod-2.2 {chmod absolute integer mode tests} {
chmod 0 {CHMOD.TMP CHMOD2.TMP}
chmod 8 {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {10 10}
test chmod-2.3 {chmod absolute integer mode tests} {
chmod 0 {CHMOD.TMP CHMOD2.TMP}
chmod 511 {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {777 777}
test chmod-2.4 {chmod absolute integer mode tests} {
chmod 0 {CHMOD.TMP CHMOD2.TMP}
chmod 438 {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {666 666}
test chmod-2.5 {chmod absolute integer mode tests} {
chmod 0 {CHMOD.TMP CHMOD2.TMP}
chmod 453 {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {705 705}
test chmod-2.6 {chmod absolute integer mode tests} {
chmod 0 CHMOD.TMP
chmod 2121 CHMOD.TMP
GetMode CHMOD.TMP
} {4111}
test chmod-2.7 {chmod absolute integer mode tests} {need_fchmod} {
chmod 0600 {CHMOD.TMP CHMOD2.TMP}
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chmod -fileid 0 [list $fh1 $fh2]
chmod -fileid 65 [list $fh1 $fh2]
close $fh1
close $fh2
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {101 101}
test chmod-2.8 {chmod absolute integer mode tests} {need_fchmod} {
chmod 0600 {CHMOD.TMP CHMOD2.TMP}
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chmod -fileid 0 [list $fh1 $fh2]
chmod -fileid 8 [list $fh1 $fh2]
close $fh1
close $fh2
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {10 10}
test chmod-2.9 {chmod absolute integer mode tests} {need_fchmod} {
chmod 0600 {CHMOD.TMP CHMOD2.TMP}
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chmod -fileid 0 [list $fh1 $fh2]
chmod -fileid 511 [list $fh1 $fh2]
close $fh1
close $fh2
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {777 777}
test chmod-2.10 {chmod absolute integer mode tests} {need_fchmod} {
chmod 0600 {CHMOD.TMP CHMOD2.TMP}
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chmod -fileid 0 [list $fh1 $fh2]
chmod -fileid 438 [list $fh1 $fh2]
close $fh1
close $fh2
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {666 666}
test chmod-2.11 {chmod absolute integer mode tests} {need_fchmod} {
chmod 0600 {CHMOD.TMP CHMOD2.TMP}
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chmod -fileid 0 [list $fh1 $fh2]
chmod -fileid 453 [list $fh1 $fh2]
close $fh1
close $fh2
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {705 705}
test chmod-2.12 {chmod absolute integer mode tests} {need_fchmod} {
chmod 0600 {CHMOD.TMP CHMOD2.TMP}
set fh [open CHMOD.TMP w]
chmod -fileid 0 $fh
chmod -fileid 2121 $fh
close $fh
GetMode CHMOD.TMP
} {4111}
# Test symbolic mode.
test chmod-3.1 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod +r CHMOD.TMP
GetMode CHMOD.TMP
} {444}
test chmod-3.2 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod +r CHMOD.TMP
chmod +w CHMOD.TMP
GetMode CHMOD.TMP
} {666}
test chmod-3.3 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod +r CHMOD.TMP
chmod +w CHMOD.TMP
chmod +x CHMOD.TMP
GetMode CHMOD.TMP
} {777}
test chmod-3.4 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod +r CHMOD.TMP
chmod +w CHMOD.TMP
chmod +x CHMOD.TMP
chmod -r CHMOD.TMP
GetMode CHMOD.TMP
} {333}
test chmod-3.5 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod +r CHMOD.TMP
chmod +w CHMOD.TMP
chmod +x CHMOD.TMP
chmod -r CHMOD.TMP
chmod -w CHMOD.TMP
GetMode CHMOD.TMP
} {111}
test chmod-3.6 {chmod symbolic mode tests} {
chmod 000 {CHMOD.TMP CHMOD2.TMP}
chmod +r {CHMOD.TMP CHMOD2.TMP}
chmod +w {CHMOD.TMP CHMOD2.TMP}
chmod +x {CHMOD.TMP CHMOD2.TMP}
chmod -r {CHMOD.TMP CHMOD2.TMP}
chmod -w {CHMOD.TMP CHMOD2.TMP}
chmod -x {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {0 0}
test chmod-3.7 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod u+x,g+x CHMOD.TMP
GetMode CHMOD.TMP
} {110}
test chmod-3.8 {chmod symbolic mode tests} {
chmod 000 {CHMOD.TMP CHMOD2.TMP}
chmod u+x,g+x {CHMOD.TMP CHMOD2.TMP}
chmod u-x,g-x {CHMOD.TMP CHMOD2.TMP}
list [GetMode CHMOD.TMP] [GetMode CHMOD2.TMP]
} {0 0}
# Can't +s on some systems
if [CheckChmod "ugo+x,ug+s" "---s--s--x"] {
test chmod-3.9 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod ugo+x,ug+s CHMOD.TMP
GetMode CHMOD.TMP
} {6111}
}
test chmod-3.10 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod a+rwx CHMOD.TMP
GetMode CHMOD.TMP
} {777}
test chmod-3.11 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod a+rwx CHMOD.TMP
chmod a-rw CHMOD.TMP
GetMode CHMOD.TMP
} {111}
test chmod-3.12 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod a=rwx CHMOD.TMP
GetMode CHMOD.TMP
} {777}
test chmod-3.13 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod u=rwx,go=rx CHMOD.TMP
GetMode CHMOD.TMP
} {755}
test chmod-3.14 {chmod symbolic mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 000 $fh
chmod -fileid +r $fh
close $fh
GetMode CHMOD.TMP
} {444}
test chmod-3.2 {chmod symbolic mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 000 $fh
chmod -fileid +r $fh
chmod -fileid +w $fh
close $fh
GetMode CHMOD.TMP
} {666}
test chmod-3.15 {chmod symbolic mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 000 $fh
chmod -fileid +r $fh
chmod -fileid +w $fh
chmod -fileid +x $fh
close $fh
GetMode CHMOD.TMP
} {777}
test chmod-3.16 {chmod symbolic mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 000 $fh
chmod -fileid +r $fh
chmod -fileid +w $fh
chmod -fileid +x $fh
chmod -fileid -r $fh
close $fh
GetMode CHMOD.TMP
} {333}
test chmod-3.17 {chmod symbolic mode tests} {need_fchmod} {
chmod 0600 CHMOD.TMP
set fh [open CHMOD.TMP w]
chmod -fileid 000 $fh
chmod -fileid +r $fh
chmod -fileid +w $fh
chmod -fileid +x $fh
chmod -fileid -r $fh
chmod -fileid -w $fh
close $fh
GetMode CHMOD.TMP
} {111}
# +t is dificult to test if not root, just make sure it execute and hope
# for the best. Doesn't even work on some systems
if [CheckChmod "u+t" "----------" "---------T"] {
test chmod-3.14 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod u+x CHMOD.TMP
chmod u+t CHMOD.TMP
set mode [GetMode CHMOD.TMP]
expr "($mode == 100) || ($mode == 1100)"
} {1}
test chmod-3.14 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod u+x CHMOD.TMP
chmod u+t CHMOD.TMP
} {}
test chmod-3.15 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod u+x CHMOD.TMP
chmod u+t CHMOD.TMP
chmod u-t CHMOD.TMP
} {}
}
test chmod-3.16 {chmod symbolic mode tests} {
chmod 000 CHMOD.TMP
chmod a+rwx CHMOD.TMP
chmod u-r,g-w,o-x CHMOD.TMP
GetMode CHMOD.TMP
} {356}
test chmod-4.1 {chmod error tests} {
list [catch {chmod +z CHMOD.TMP} msg] $msg
} {1 {invalid file mode "+z"}}
test chmod-4.2 {chmod error tests} {
list [catch {chmod} msg] $msg
} {1 {wrong # args: chmod [-fileid] mode filelist}}
test chmod-4.3 {chmod error tests} {need_fchmod} {
list [catch {chmod -fileid +w BAD} msg] $msg
} {1 {can not find channel named "BAD"}}
test chmod-4.4 {chmod error tests} {need_fchmod} {
list [catch {chmod -file -w CHMOD.TMP} msg] $msg
} {1 {wrong # args: chmod [-fileid] mode filelist}}
# chown and chgrp tests
set myUID [id userid]
set myGID [id groupid]
#
# Some machines have problems with changing group ids on files (even to your
# own) if you are not root. On some it works for chown but not fchown (Ultix).
#
SetUpTestFiles
set ::tcltest::testConstraints(chownWorks) 1
if {[catch {chown [id userid] CHMOD.TMP} msg ] ||
[catch {chgrp [id groupid] CHMOD.TMP} msg ]} {
puts "********************************************************************"
puts "Can't do chown or chgrp even when current and new group id are"
puts "ours. You probably have to be root. Some chown/chgrp tests skipped"
puts "on this system."
puts " $msg"
puts "********************************************************************"
set ::tcltest::testConstraints(chownWorks) 0
}
if [infox have_fchown] {
set ::tcltest::testConstraints(fchownWorks) 1
set fh [open CHMOD.TMP w]
if {[catch {chown -fileid [id userid] $fh} msg ] ||
[catch {chgrp -fileid [id groupid] $fh} msg ]} {
puts "****************************************************************"
puts "Can't do chown or chgrp with -fileid even when current and new"
puts "groupid are ours. You probably have to be root. Some chown/chgrp"
puts "tests skipped on this system."
puts " $msg"
puts "****************************************************************"
set ::tcltest::testConstraints(fchownWorks) 0
}
close $fh
}
test chmod-5.1 {chown tests} {chownWorks} {
SetUpTestFiles
chown [id user] {CHMOD.TMP CHMOD2.TMP}
list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
} [list $myUID $myUID]
test chmod-5.2 {chown tests} {chownWorks} {
chown [id userid] {CHMOD.TMP CHMOD2.TMP}
list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
} [list $myUID $myUID]
test chmod-5.3 {chown tests} {chownWorks} {
chown [list [id userid] [id groupid]] {CHMOD.TMP CHMOD2.TMP}
list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
} [list [list $myUID $myGID] [list $myUID $myGID]]
test chmod-5.4 {chown tests} {chownWorks} {
chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
} [list [list $myUID $myGID] [list $myUID $myGID]]
test chmod-5.5 {chown tests} {chownWorks} {
chown [list [id user] [id group]] {CHMOD.TMP CHMOD2.TMP}
list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
} [list [list $myUID $myGID] [list $myUID $myGID]]
test chmod-5.6 {chown tests} {need_fchown && fchownWorks} {
SetUpTestFiles
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chown -fileid [id user] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
} [list $myUID $myUID]
test chmod-5.7 {chown tests} {need_fchown && fchownWorks} {
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chown -fileid [id userid] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetUID CHMOD.TMP] [GetUID CHMOD2.TMP]
} [list $myUID $myUID]
test chmod-5.8 {chown tests} {need_fchown && fchownWorks} {
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chown -fileid [list [id userid] [id groupid]] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
} [list [list $myUID $myGID] [list $myUID $myGID]]
test chmod-5.9 {chown tests} {need_fchown && fchownWorks} {
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chown -fileid [list [id user] [id group]] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
} [list [list $myUID $myGID] [list $myUID $myGID]]
test chmod-5.10 {chown tests} {need_fchown && fchownWorks} {
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chown -fileid [list [id user] [id group]] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetUIDGID CHMOD.TMP] [GetUIDGID CHMOD2.TMP]
} [list [list $myUID $myGID] [list $myUID $myGID]]
SetUpTestFiles
test chmod-6.1 {chown error tests} {
list [catch {chown XXXXXXXXX CHMOD.TMP} msg] $msg
} {1 {unknown user id: XXXXXXXXX}}
test chmod-6.2 {chown error tests} {
list [catch {chown [list XXXXXXXXX [id groupid]] CHMOD.TMP} msg] $msg
} {1 {unknown user id: XXXXXXXXX}}
test chmod-6.3 {chown error tests} {
list [catch {chown [list [id user] XXXXXXXXX] CHMOD.TMP} msg] $msg
} {1 {unknown group id: XXXXXXXXX}}
test chmod-6.4 {chown error tests} {
list [catch {chown {XXXXXXXXX YYYY} CHMOD.TMP} msg] $msg
} {1 {unknown user id: XXXXXXXXX}}
test chmod-6.5 {chown error tests} {
list [catch {chown} msg] $msg
} {1 {wrong # args: chown [-fileid] user|{user group} filelist}}
test chmod-6.6 {chown error tests} {need_fchown} {
list [catch {chown -fileid $myUID BAD} msg] $msg
} {1 {can not find channel named "BAD"}}
test chmod-6.6 {chown error tests} {need_fchown} {
list [catch {chown -fid $myUID CHMOD.TMP} msg] $msg
} {1 {Invalid option "-fid", expected "-fileid"}}
test chmod-7.1 {chgrp tests} {chownWorks} {
chgrp [id group] {CHMOD.TMP CHMOD2.TMP}
list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
} [list $myGID $myGID]
test chmod-7.2 {chgrp tests} {chownWorks} {
chgrp [id groupid] {CHMOD.TMP CHMOD2.TMP}
list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
} [list $myGID $myGID]
test chmod-7.3 {chgrp tests} {need_fchown && fchownWorks} {
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chgrp -fileid [id group] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
} [list $myGID $myGID]
test chmod-7.4 {chgrp tests} {need_fchown && fchownWorks} {
set fh1 [open CHMOD.TMP w]
set fh2 [open CHMOD2.TMP w]
chgrp -fileid [id groupid] [list $fh1 $fh2]
close $fh1
close $fh2
list [GetGID CHMOD.TMP] [GetGID CHMOD2.TMP]
} [list $myGID $myGID]
test chmod-8.1 {chgrp error tests} {
list [catch {chgrp} msg] $msg
} {1 {wrong # args: chgrp [-fileid] group filelist}}
test chmod-8.2 {chgrp error tests} {
list [catch {chgrp XXXXXXXXX CHMOD.TMP} msg] $msg
} {1 {unknown group id: XXXXXXXXX}}
test chmod-8.3 {chown error tests} {need_fchown} {
list [catch {chgrp -fileid $myGID BAD} msg] $msg
} {1 {can not find channel named "BAD"}}
test chmod-8.4 {chown error tests} {need_fchown} {
list [catch {chgrp -fid $myGID CHMOD.TMP} msg] $msg
} {1 {Invalid option "-fid", expected "-fileid"}}
TestRemove CHECK.TMP CHMOD.TMP CHMOD2.TMP
# cleanup
::tcltest::cleanupTests
return
|