file-temp 1.2.1 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +1 -0
- data.tar.gz.sig +0 -0
- data/{CHANGES → CHANGES.rdoc} +33 -0
- data/LICENSE +177 -0
- data/MANIFEST.rdoc +13 -0
- data/README.rdoc +66 -0
- data/Rakefile +8 -47
- data/certs/djberg96_pub.pem +26 -0
- data/file-temp.gemspec +22 -14
- data/lib/file-temp.rb +1 -0
- data/lib/file/{temp_java.rb → java/temp.rb} +14 -16
- data/lib/file/temp.rb +11 -2
- data/lib/file/unix/temp.rb +106 -0
- data/lib/file/windows/temp.rb +217 -0
- data/spec/file_temp_spec.rb +159 -0
- metadata +75 -32
- metadata.gz.sig +0 -0
- data/MANIFEST +0 -9
- data/README +0 -61
- data/lib/file/temp_c.rb +0 -254
- data/test/test_file_temp.rb +0 -135
data/test/test_file_temp.rb
DELETED
@@ -1,135 +0,0 @@
|
|
1
|
-
######################################################################
|
2
|
-
# test_file_temp.rb
|
3
|
-
#
|
4
|
-
# Test suite for the file-temp library. These tests should be run
|
5
|
-
# via the 'rake test' task.
|
6
|
-
######################################################################
|
7
|
-
require 'rubygems'
|
8
|
-
require 'test-unit'
|
9
|
-
require 'file/temp'
|
10
|
-
|
11
|
-
class TC_File_Temp < Test::Unit::TestCase
|
12
|
-
WINDOWS = File::ALT_SEPARATOR
|
13
|
-
|
14
|
-
def setup
|
15
|
-
@dir = File::Temp::TMPDIR
|
16
|
-
@template = 'file-temp-test-XXXXX'
|
17
|
-
@fh = nil
|
18
|
-
|
19
|
-
# Because Dir[] doesn't work right with backslashes
|
20
|
-
@dir = @dir.tr("\\", "/") if WINDOWS
|
21
|
-
end
|
22
|
-
|
23
|
-
test "library version is set to expected value" do
|
24
|
-
assert_equal('1.2.1', File::Temp::VERSION)
|
25
|
-
end
|
26
|
-
|
27
|
-
# Fails with JRuby, not sure why.
|
28
|
-
test "library works as expected with multiple threads" do
|
29
|
-
threads = []
|
30
|
-
assert_nothing_raised{ 100.times{ threads << Thread.new{ File::Temp.new }}}
|
31
|
-
assert_nothing_raised{ threads.each{ |t| t.join } }
|
32
|
-
end
|
33
|
-
|
34
|
-
test "TMPDIR constant is defined" do
|
35
|
-
assert_not_nil(File::Temp::TMPDIR)
|
36
|
-
assert_kind_of(String, File::Temp::TMPDIR)
|
37
|
-
end
|
38
|
-
|
39
|
-
test "constructor works as expected with default auto delete option" do
|
40
|
-
assert_nothing_raised{
|
41
|
-
@fh = File::Temp.new
|
42
|
-
@fh.print "hello"
|
43
|
-
@fh.close
|
44
|
-
}
|
45
|
-
end
|
46
|
-
|
47
|
-
test "constructor works as expected with false auto delete option" do
|
48
|
-
assert_nothing_raised{
|
49
|
-
@fh = File::Temp.new(false)
|
50
|
-
@fh.print "hello"
|
51
|
-
@fh.close
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
test "constructor accepts and uses an optional template as expected" do
|
56
|
-
assert_nothing_raised{ File::Temp.new(false, 'temp_foo_XXXXXX').close }
|
57
|
-
assert_true(Dir["#{@dir}/temp_foo*"].length >= 1)
|
58
|
-
end
|
59
|
-
|
60
|
-
test "constructor with false auto delete and block works as expected" do
|
61
|
-
assert_nothing_raised{ File::Temp.open(false, 'temp_foo_XXXXXX'){ |fh| fh.puts "hello" } }
|
62
|
-
assert_true(Dir["#{@dir}/temp_foo*"].length >= 1)
|
63
|
-
end
|
64
|
-
|
65
|
-
test "second argument to constructor must be a string" do
|
66
|
-
assert_raise(TypeError, ArgumentError){ @fh = File::Temp.new(false, 1) }
|
67
|
-
end
|
68
|
-
|
69
|
-
test "an error is raised if a custom template is invalid" do
|
70
|
-
assert_raise(Errno::EINVAL){ File::Temp.new(false, 'xx') }
|
71
|
-
end
|
72
|
-
|
73
|
-
test "constructor accepts a maximum of two arguments" do
|
74
|
-
assert_raise(ArgumentError){ @fh = File::Temp.new(true, 'temp_bar_XXXXX', 1) }
|
75
|
-
end
|
76
|
-
|
77
|
-
test "temp_name basic functionality" do
|
78
|
-
assert_respond_to(File::Temp, :temp_name)
|
79
|
-
assert_nothing_raised{ File::Temp.temp_name }
|
80
|
-
assert_kind_of(String, File::Temp.temp_name)
|
81
|
-
end
|
82
|
-
|
83
|
-
test "temp_name returns expected value" do
|
84
|
-
if File::ALT_SEPARATOR
|
85
|
-
assert_match(/^.*?\d*?tmp/, File.extname(File::Temp.temp_name))
|
86
|
-
else
|
87
|
-
assert_equal('.tmp', File.extname(File::Temp.temp_name))
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
test "temp path basic functionality" do
|
92
|
-
@fh = File::Temp.new
|
93
|
-
assert_respond_to(@fh, :path)
|
94
|
-
end
|
95
|
-
|
96
|
-
test "temp path is nil if delete option is true" do
|
97
|
-
@fh = File::Temp.new
|
98
|
-
assert_nil(@fh.path)
|
99
|
-
end
|
100
|
-
|
101
|
-
test "temp path is not nil if delete option is false" do
|
102
|
-
@fh = File::Temp.new(false)
|
103
|
-
assert_not_nil(@fh.path)
|
104
|
-
end
|
105
|
-
|
106
|
-
test "ffi functions are private" do
|
107
|
-
methods = File::Temp.methods(false).map{ |e| e.to_s }
|
108
|
-
assert_false(methods.include?('_fileno'))
|
109
|
-
assert_false(methods.include?('mkstemp'))
|
110
|
-
assert_false(methods.include?('_umask'))
|
111
|
-
assert_false(methods.include?('fclose'))
|
112
|
-
assert_false(methods.include?('strerror'))
|
113
|
-
assert_false(methods.include?('tmpnam'))
|
114
|
-
assert_false(methods.include?('CloseHandle'))
|
115
|
-
assert_false(methods.include?('CreateFileA'))
|
116
|
-
assert_false(methods.include?('DeleteFileA'))
|
117
|
-
assert_false(methods.include?('GetTempPathA'))
|
118
|
-
assert_false(methods.include?('GetTempFileNameA'))
|
119
|
-
end
|
120
|
-
|
121
|
-
def teardown
|
122
|
-
@dir = nil
|
123
|
-
@template = nil
|
124
|
-
@fh.close if @fh && !@fh.closed?
|
125
|
-
@fh = nil
|
126
|
-
|
127
|
-
Dir["temp_*"].each{ |f| File.delete(f) }
|
128
|
-
Dir["rb_file_temp_*"].each{ |f| File.delete(f) }
|
129
|
-
|
130
|
-
Dir.chdir(File::Temp::TMPDIR) do
|
131
|
-
Dir["temp_*"].each{ |f| File.delete(f) }
|
132
|
-
Dir["rb_file_temp_*"].each{ |f| File.delete(f) }
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|