File: testEnv.rb

package info (click to toggle)
jruby 1.5.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: squeeze
  • size: 46,252 kB
  • ctags: 72,039
  • sloc: ruby: 398,155; java: 169,482; yacc: 3,782; xml: 2,469; ansic: 415; sh: 279; makefile: 78; tcl: 40
file content (85 lines) | stat: -rw-r--r-- 2,052 bytes parent folder | download | duplicates (4)
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
require 'test/minirunit'

is_windows = RUBY_PLATFORM =~ /mswin/i || (RUBY_PLATFORM =~ /java/i && ENV_JAVA['os.name'] =~ /windows/i)

#test_check('test_bracket')
test_equal(nil, ENV['test'])
test_equal(nil, ENV['TEST'])

ENV['test'] = 'foo'

test_equal('foo', ENV['test'])
test_equal(is_windows ? 'foo' : nil, ENV['TEST'])

ENV['TEST'] = 'bar'
test_equal('bar', ENV['TEST'])
test_equal(is_windows ? 'bar' : 'foo', ENV['test'])

test_exception(TypeError) {
  tmp = ENV[1]
}

test_exception(TypeError) {
  ENV[1] = 'foo'
}

test_exception(TypeError) {
  ENV['test'] = 0
}


#test_check('has_value')
val = 'a'
val.succ! while ENV.has_value?(val) && ENV.has_value?(val.upcase)
ENV['test'] = val[0...-1]

test_equal(false, ENV.has_value?(val))
test_equal(false, ENV.has_value?(val.upcase))

ENV['test'] = val

test_equal(true, ENV.has_value?(val))
test_equal(false, ENV.has_value?(val.upcase))

ENV['test'] = val.upcase
test_equal(false, ENV.has_value?(val))
test_equal(true, ENV.has_value?(val.upcase))


#test_check('index')
val = 'a'
val.succ! while ENV.has_value?(val) && ENV.has_value?(val.upcase)
ENV['test'] = val[0...-1]

test_equal(nil, ENV.index(val))
test_equal(nil, ENV.index(val.upcase))
ENV['test'] = val
test_equal('test', ENV.index(val))

test_equal(nil, ENV.index(val.upcase))
ENV['test'] = val.upcase
test_equal(nil, ENV.index(val))
test_equal('test', ENV.index(val.upcase))

#nil values are ok (corresponding key will be deleted) 
#nil keys are not ok
test_exception(TypeError) {ENV[nil]}
test_exception(TypeError) {ENV[nil] = "foo"}

ENV['test'] = nil
test_equal(nil, ENV['test'])
test_equal(false, ENV.has_key?('test'))

name = (ENV['OS'] =~ /\AWin/i ? '%__JRUBY_T1%' : '$__JRUBY_T1')
expected = (ENV['OS'] =~ /\AWin/i ? '%__JRUBY_T1%' : '')
v = `echo #{name}`.chomp
test_equal expected,v
ENV['__JRUBY_T1'] = "abc"
v = `echo #{name}`.chomp
test_equal "abc",v

# Disabled for shell-character fixes; see JRUBY-3097
#test_equal "abc", `jruby -e "puts ENV[%{__JRUBY_T1}]"`.chomp

# JRUBY-2393
test_ok(ENV.object_id != ENV.to_hash.object_id)