home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / devel / tcl / tclx7_31.z / tclx7_31 / tcldev / tclX7.3a-p1 / tests / dup.test < prev    next >
Encoding:
Text File  |  1994-01-23  |  2.2 KB  |  94 lines

  1. #
  2. # dup.test
  3. #
  4. # Tests for the dup command.
  5. #---------------------------------------------------------------------------
  6. # Copyright 1992-1993 Karl Lehenbauer and Mark Diekhans.
  7. #
  8. # Permission to use, copy, modify, and distribute this software and its
  9. # documentation for any purpose and without fee is hereby granted, provided
  10. # that the above copyright notice appear in all copies.  Karl Lehenbauer and
  11. # Mark Diekhans make no representations about the suitability of this
  12. # software for any purpose.  It is provided "as is" without express or
  13. # implied warranty.
  14. #------------------------------------------------------------------------------
  15. # $Id: dup.test,v 3.1 1994/01/11 06:31:35 markd Exp $
  16. #------------------------------------------------------------------------------
  17. #
  18.  
  19. if {[info procs test] != "test"} then {source testlib.tcl}
  20.  
  21.  
  22. # Create a test file
  23.  
  24. unlink -nocomplain {DUP.TMP DUP2.TMP}
  25.  
  26. set testFH [open DUP.TMP w]
  27. for {set cnt 0} {$cnt < 100} {incr cnt} {
  28.      puts $testFH [GenRec $cnt]
  29. }
  30. close $testFH
  31.  
  32. Test dup-1.1 {dup tests} {
  33.     set testFH [open DUP.TMP]
  34.     set testFH2 [dup $testFH]
  35.     gets $testFH2 testRec
  36.     close $testFH
  37.     close $testFH2
  38.     set testRec
  39. } 0 [GenRec 0]
  40.  
  41. Test dup-1.2 {dup tests} {
  42.     set testFH [open DUP.TMP]
  43.     set testFH2 [open DUP2.TMP w]
  44.     set testFH2 [dup $testFH $testFH2]
  45.     gets $testFH2 testRec
  46.     close $testFH
  47.     close $testFH2
  48.     set testRec
  49. } 0 [GenRec 0]
  50.  
  51. set data {{now is the time}    {for all good programmers} 
  52.           {to come to the aid} {of their software}}
  53. set inFH [open INCMDS.TMP w]
  54. catch {unlink OUTPUT.TMP}
  55. foreach line $data {
  56.     puts $inFH "puts stdout \"$line\""
  57. }
  58. puts $inFH {flush stdout}
  59. puts $inFH {exit 0}
  60. close $inFH
  61.  
  62. flush stdout
  63. flush stderr
  64.  
  65. if {[set childPid [fork]] == 0} {
  66.     set inFH  [open INCMDS.TMP r]
  67.     set outFH [open OUTPUT.TMP w]
  68.  
  69.     dup $inFH stdin
  70.     close $inFH
  71.  
  72.     dup $outFH stdout
  73.     close $outFH
  74.         
  75.     execl $TCL_PROGRAM [list -qc {commandloop {} {}}]
  76.     puts stderr "execl failed"
  77.     exit 1
  78. }
  79.  
  80. Test dup-1.3 {dup tests} {
  81.     wait $childPid
  82. } 0 "$childPid EXIT 0"
  83.  
  84. set outFH [open OUTPUT.TMP r]
  85. foreach line $data {
  86.     Test dup-1.4 {dup tests} {
  87.         gets $outFH
  88.     } 0 $line
  89. }
  90. close $outFH
  91.  
  92. unlink -nocomplain {DUP.TMP DUP2.TMP INCMDS.TMP OUTPUT.TMP}
  93.  
  94.