⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pkgmkindex.test

📁 tcl是工具命令语言
💻 TEST
📖 第 1 页 / 共 2 页
字号:
# This file contains tests for the pkg_mkIndex command.# Note that the tests are limited to Tcl scripts only, there are no shared# libraries against which to test.## Sourcing this file into Tcl runs the tests and generates output for# errors.  No output means no errors were found.## Copyright (c) 1998-1999 by Scriptics Corporation.# All rights reserved.## RCS: @(#) $Id: pkgMkIndex.test,v 1.23 2002/07/06 18:19:46 dgp Exp $if {[lsearch [namespace children] ::tcltest] == -1} {    package require tcltest 2    namespace import -force ::tcltest::*}set fullPkgPath [makeDirectory pkg]namespace eval pkgtest {    # Namespace for procs we can discard}# pkgtest::parseArgs --##  Parse an argument list.## Arguments:#  <flags>	(optional) arguments starting with a dash are collected#		as options to pkg_mkIndex and passed to pkg_mkIndex.#  dirPath	the directory to index#  pattern0	pattern to index#  ...		pattern to index#  patternN	pattern to index## Results:#  Returns a three element list:#    0: the options#    1: the directory to index#    2: the patterns listproc pkgtest::parseArgs { args } {    set options ""    set argc [llength $args]    for {set iarg 0} {$iarg < $argc} {incr iarg} {	set a [lindex $args $iarg]	if {[regexp {^-} $a]} {	    lappend options $a	    if {[string compare -load $a] == 0} {		incr iarg		lappend options [lindex $args $iarg]	    }	} else {	    break	}    }    set dirPath [lindex $args $iarg]    incr iarg    set patternList [lrange $args $iarg end]    return [list $options $dirPath $patternList]}# pkgtest::parseIndex --##  Loads a pkgIndex.tcl file, records all the calls to "package ifneeded".## Arguments:#  filePath	path to the pkgIndex.tcl file.## Results:#  Returns a list, in "array set/get" format, where the keys are the package#  name and version (in the form "$name:$version"), and the values the rest#  of the command line.proc pkgtest::parseIndex { filePath } {    # create a slave interpreter, where we override "package ifneeded"    set slave [interp create]    if {[catch {	$slave eval {	    rename package package_original	    proc package { args } {		if {[string compare [lindex $args 0] ifneeded] == 0} {		    set pkg [lindex $args 1]		    set ver [lindex $args 2]		    set ::PKGS($pkg:$ver) [lindex $args 3]		} else {		    return [eval package_original $args]		}	    }	    array set ::PKGS {}	}	set dir [file dirname $filePath]	$slave eval {set curdir [pwd]}	$slave eval [list cd $dir]	$slave eval [list set dir $dir]	$slave eval [list source [file tail $filePath]]	$slave eval {cd $curdir}	# Create the list in sorted order, so that we don't get spurious	# errors because the order has changed.	array set P {}	foreach {k v} [$slave eval {array get ::PKGS}] {	    set P($k) $v	}	set PKGS ""	foreach k [lsort [array names P]] {	    lappend PKGS $k $P($k)	}    } err]} {	set ei $::errorInfo	set ec $::errorCode	catch {interp delete $slave}	error $ei $ec    }    interp delete $slave    return $PKGS}# pkgtest::createIndex --##  Runs pkg_mkIndex for the given directory and set of patterns.#  This procedure deletes any pkgIndex.tcl file in the target directory,#  then runs pkg_mkIndex.## Arguments:#  <flags>	(optional) arguments starting with a dash are collected#		as options to pkg_mkIndex and passed to pkg_mkIndex.#  dirPath	the directory to index#  pattern0	pattern to index#  ...		pattern to index#  patternN	pattern to index## Results:#  Returns a two element list:#    0: 1 if the procedure encountered an error, 0 otherwise.#    1: the error result if element 0 was 1proc pkgtest::createIndex { args } {    set parsed [eval parseArgs $args]    set options [lindex $parsed 0]    set dirPath [lindex $parsed 1]    set patternList [lindex $parsed 2]    file mkdir $dirPath    if {[catch {	file delete [file join $dirPath pkgIndex.tcl]	eval pkg_mkIndex $options [list $dirPath] $patternList    } err]} {	return [list 1 $err]    }    return [list 0 {}]}# makePkgList --##  Takes the output of a pkgtest::parseIndex call, filters it and returns a#  cleaned up list of packages and their actions.## Arguments:#  inList	output from a pkgtest::parseIndex.## Results:#  Returns a list of two element lists:#    0: the name:version#    1: a list describing the package.#	For tclPkgSetup packages it consists of:#	 0: the keyword tclPkgSetup#	 1: the first file to source, with its exported procedures#	 2: the second file ...#	 N: the N-1st file ...proc makePkgList { inList } {    set pkgList ""    foreach {k v} $inList {	switch [lindex $v 0] {	    tclPkgSetup {		set l tclPkgSetup		foreach s [lindex $v 4] {		    lappend l $s		}	    }	    source {		set l $v	    }	    default {		error "can't handle $k $v"	    }	}	lappend pkgList [list $k $l]    }    return $pkgList}# pkgtest::runIndex --##  Runs pkg_mkIndex, parses the generated index file.## Arguments:#  <flags>	(optional) arguments starting with a dash are collected#		as options to pkg_mkIndex and passed to pkg_mkIndex.#  dirPath	the directory to index#  pattern0	pattern to index#  ...		pattern to index#  patternN	pattern to index## Results:#  Returns a two element list:#    0: 1 if the procedure encountered an error, 0 otherwise.#    1: if no error, this is the parsed generated index file, in the format#	returned by pkgtest::parseIndex.#	If error, this is the error result.proc pkgtest::runCreatedIndex {rv args} {    if {[lindex $rv 0] == 0} {	set parsed [eval parseArgs $args]	set dirPath [lindex $parsed 1]	set idxFile [file join $dirPath pkgIndex.tcl]	if {[catch {	    set result [list 0 [makePkgList [parseIndex $idxFile]]]	} err]} {	    set result [list 1 $err]	} 	file delete $idxFile    } else {	set result $rv    }    return $result}proc pkgtest::runIndex { args } {    set rv [eval createIndex $args]    return [eval [list runCreatedIndex $rv] $args]}# If there is no match to the patterns, make sure the directory hasn't# changed on ustest pkgMkIndex-1.1 {nothing matches pattern - current dir is the same} {    list [pkgtest::runIndex -lazy $fullPkgPath nomatch.tcl] [pwd]} [list {1 {no files matched glob pattern "nomatch.tcl"}} [pwd]]makeFile {#  This is a simple package, just to check basic functionality.package provide simple 1.0namespace eval simple {    namespace export lower upper}proc simple::lower { stg } {    return [string tolower $stg]}proc simple::upper { stg } {    return [string toupper $stg]}} [file join pkg simple.tcl]test pkgMkIndex-2.1 {simple package} {    pkgtest::runIndex -lazy $fullPkgPath simple.tcl} {0 {{simple:1.0 {tclPkgSetup {simple.tcl source {::simple::lower ::simple::upper}}}}}}test pkgMkIndex-2.2 {simple package - use -direct} {    pkgtest::runIndex -direct $fullPkgPath simple.tcl} "0 {{simple:1.0 {[list source [file join $fullPkgPath simple.tcl]]}}}"test pkgMkIndex-2.3 {simple package - direct loading is default} {    pkgtest::runIndex $fullPkgPath simple.tcl} "0 {{simple:1.0 {[list source [file join $fullPkgPath simple.tcl]]}}}"removeFile [file join pkg simple.tcl]makeFile {#  Contains global symbols, used to check that they don't have a leading ::package provide global 1.0proc global_lower { stg } {    return [string tolower $stg]}proc global_upper { stg } {    return [string toupper $stg]}} [file join pkg global.tcl]test pkgMkIndex-3.1 {simple package with global symbols} {    pkgtest::runIndex -lazy $fullPkgPath global.tcl} {0 {{global:1.0 {tclPkgSetup {global.tcl source {global_lower global_upper}}}}}}removeFile [file join pkg global.tcl]makeFile {#  This package is required by pkg1.#  This package is split into two files, to test packages that are split#  over multiple files.package provide pkg2 1.0namespace eval pkg2 {    namespace export p2-1}proc pkg2::p2-1 { num } {    return [expr $num * 2]}} [file join pkg pkg2_a.tcl]makeFile {#  This package is required by pkg1.#  This package is split into two files, to test packages that are split#  over multiple files.package provide pkg2 1.0namespace eval pkg2 {    namespace export p2-2}proc pkg2::p2-2 { num } {    return [expr $num * 3]}} [file join pkg pkg2_b.tcl]test pkgMkIndex-4.1 {split package} {    pkgtest::runIndex -lazy $fullPkgPath pkg2_a.tcl pkg2_b.tcl} {0 {{pkg2:1.0 {tclPkgSetup {pkg2_a.tcl source ::pkg2::p2-1} {pkg2_b.tcl source ::pkg2::p2-2}}}}}test pkgMkIndex-4.2 {split package - direct loading} {    pkgtest::runIndex -direct $fullPkgPath pkg2_a.tcl pkg2_b.tcl} "0 {{pkg2:1.0 {[list source [file join $fullPkgPath pkg2_a.tcl]][list source [file join $fullPkgPath pkg2_b.tcl]]}}}"# Add the direct1 directory to auto_path, so that the direct1 package # can be found.set direct1 [makeDirectory direct1]lappend auto_path $direct1makeFile {#  This is referenced by pkgIndex.tcl as a -direct script.package provide direct1 1.0

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -