Skip to content
Tcl Source Code Artifact [83176f0dee]
Login

Artifact [83176f0dee]

Artifact 83176f0dee40d2afd27f7640cff96b4a597bc954:

Attachment "nsbug.tcl" to ticket [2898722fff] added by bharder on 2009-11-17 05:24:59.
package require tcltest
namespace import tcltest::*

;# author: Bradley C. Harder, Method Logic Digital
;# purpose: This test suite is to demonstrate a bug in Tcl 8.5.7
;# whereby a newly defined proc seems unnoticed (when called immediately
;# after definition) within a namespace when [namespace path] is also
;# defined. Subsequent calls to proc from within same namespace work
;# as advertised.
;# Permission is hereby granted to use and distribute these tests
;# under same license as Tcl itself.

test nspath-1.1 {
  Define a proc "mycmd" in namespace ::fu, call "mycmd"
} -body {
  namespace eval ::fu {
    proc mycmd {} {
      namespace current
    }
    mycmd
  }
} -result "::fu"

test nspath-2.1 {
  Call [mycmd] from a namespace w/o a local definition, and no
  [namespace path] setup. Should return error.
} -body {
  namespace eval ::fu::bar {
    mycmd
  }
} -match glob -returnCodes 1 -result "invalid command*"

test nspath-3.1 {
  In ::fu::bar, setup [namespace path], call [mycmd].
} -body {
  namespace eval ::fu::bar {
    namespace path [namespace parent]
    mycmd
  }
} -result "::fu"

test nspath-4.1 {
  From ::fu::bar, define proc "mycmd", and immediately call it.
  *NOTE* -- [namespace path] was previously set in test "nspath-3".
} -body {
  namespace eval ::fu::bar {
    proc mycmd {} {
      namespace current
    }
    mycmd
  }
} -result "::fu::bar"

test nspath-5.1 {
  From ::fu::bar, call proc "mycmd" which was previously defined
  in test "nspath-4".
} -body {
  namespace eval ::fu::bar {
    mycmd
  }
} -result "::fu::bar"

cleanupTests