OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [tests/] [env.test] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# Commands covered:  none (tests environment variable implementation)
2
#
3
# This file contains a collection of tests for one or more of the Tcl
4
# built-in commands.  Sourcing this file into Tcl runs the tests and
5
# generates output for errors.  No output means no errors were found.
6
#
7
# Copyright (c) 1991-1993 The Regents of the University of California.
8
# Copyright (c) 1994 Sun Microsystems, Inc.
9
#
10
# See the file "license.terms" for information on usage and redistribution
11
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12
#
13
# RCS: @(#) $Id: env.test,v 1.1.1.1 2002-01-16 10:25:35 markom Exp $
14
 
15
if {[string compare test [info procs test]] == 1} then {source defs}
16
 
17
#
18
# These tests will run on any platform (and indeed crashed
19
# on the Mac).  So put them before you test for the existance
20
# of exec.
21
#
22
test env-1.1 {propagation of env values to child interpreters} {
23
    catch {interp delete child}
24
    catch {unset env(test)}
25
    interp create child
26
    set env(test) garbage
27
    set return [child eval {set env(test)}]
28
    interp delete child
29
    unset env(test)
30
    set return
31
} {garbage}
32
#
33
# This one crashed on Solaris under Tcl8.0, so we only
34
# want to make sure it runs.
35
#
36
test env-1.2 {lappend to env value} {
37
    catch {unset env(test)}
38
    set env(test) aaaaaaaaaaaaaaaa
39
    append env(test) bbbbbbbbbbbbbb
40
    unset env(test)
41
} {}
42
if {[info commands exec] == ""} {
43
    puts "exec not implemented for this machine"
44
    return
45
}
46
 
47
if {$tcl_platform(os) == "Win32s"} {
48
    puts "Cannot run multiple copies of tcl at the same time under Win32s"
49
    return
50
}
51
 
52
set f [open printenv w]
53
puts $f {
54
    proc lrem {listname name} {
55
        upvar $listname list
56
        set i [lsearch $list $name]
57
        if {$i >= 0} {
58
            set list [lreplace $list $i $i]
59
        }
60
        return $list
61
    }
62
 
63
    set names [lsort [array names env]]
64
    if {$tcl_platform(platform) == "windows"} {
65
        lrem names HOME
66
        lrem names COMSPEC
67
        lrem names ComSpec
68
        lrem names ""
69
    }
70
    foreach name {TCL_LIBRARY PATH LD_LIBRARY_PATH SHLIB_PATH} {
71
        lrem names $name
72
    }
73
    foreach p $names {
74
        puts "$p=$env($p)"
75
    }
76
}
77
close $f
78
 
79
proc getenv {} {
80
    global printenv tcltest
81
    catch {exec $tcltest printenv} out
82
    if {$out == "child process exited abnormally"} {
83
        set out {}
84
    }
85
    return $out
86
}
87
 
88
# Save the current environment variables at the start of the test.
89
 
90
foreach name [array names env] {
91
    set env2($name) $env($name)
92
    unset env($name)
93
}
94
 
95
# Added the following lines so that child tcltest can actually find its
96
# library if the initial tcltest is run from a non-standard place.
97
# ('saved' env vars)
98
foreach name {TCL_LIBRARY PATH LD_LIBRARY_PATH SHLIB_PATH} {
99
  if {[info exists env2($name)]} {
100
     set env($name) $env2($name);
101
  }
102
}
103
 
104
test env-2.1 {adding environment variables} {
105
    getenv
106
} {}
107
 
108
set env(NAME1) "test string"
109
test env-2.2 {adding environment variables} {
110
    getenv
111
} {NAME1=test string}
112
 
113
set env(NAME2) "more"
114
test env-2.3 {adding environment variables} {
115
    getenv
116
} {NAME1=test string
117
NAME2=more}
118
 
119
set env(XYZZY) "garbage"
120
test env-2.4 {adding environment variables} {
121
    getenv
122
} {NAME1=test string
123
NAME2=more
124
XYZZY=garbage}
125
 
126
set env(NAME2) "new value"
127
test env-3.1 {changing environment variables} {
128
    getenv
129
} {NAME1=test string
130
NAME2=new value
131
XYZZY=garbage}
132
 
133
unset env(NAME2)
134
test env-4.1 {unsetting environment variables} {
135
    getenv
136
} {NAME1=test string
137
XYZZY=garbage}
138
unset env(NAME1)
139
test env-4.2 {unsetting environment variables} {
140
    getenv
141
} {XYZZY=garbage}
142
 
143
# Restore the environment variables at the end of the test.
144
 
145
foreach name [array names env] {
146
    unset env($name)
147
}
148
foreach name [array names env2] {
149
    set env($name) $env2($name)
150
}
151
 
152
file delete printenv

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.