hotplate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/Rakefile +1 -0
  4. data/bin/toast +2 -0
  5. data/hotplate.gemspec +30 -0
  6. data/lib/hotplate/cli/build.rb +51 -0
  7. data/lib/hotplate/cli/init.rb +64 -0
  8. data/lib/hotplate/cli/main.rb +39 -0
  9. data/lib/hotplate/gems/rubyzip-1.1.7/README.md +271 -0
  10. data/lib/hotplate/gems/rubyzip-1.1.7/Rakefile +19 -0
  11. data/lib/hotplate/gems/rubyzip-1.1.7/TODO +15 -0
  12. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/central_directory.rb +208 -0
  13. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/compressor.rb +10 -0
  14. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/constants.rb +63 -0
  15. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/encryption.rb +11 -0
  16. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/null_encryption.rb +45 -0
  17. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/crypto/traditional_encryption.rb +99 -0
  18. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/decompressor.rb +13 -0
  19. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/deflater.rb +32 -0
  20. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/dos_time.rb +49 -0
  21. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry.rb +696 -0
  22. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/entry_set.rb +86 -0
  23. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/errors.rb +16 -0
  24. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/generic.rb +43 -0
  25. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/ntfs.rb +92 -0
  26. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/old_unix.rb +45 -0
  27. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/universal_time.rb +47 -0
  28. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/unix.rb +38 -0
  29. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64.rb +67 -0
  30. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field/zip64_placeholder.rb +16 -0
  31. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/extra_field.rb +101 -0
  32. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/file.rb +436 -0
  33. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/filesystem.rb +626 -0
  34. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/inflater.rb +66 -0
  35. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/input_stream.rb +164 -0
  36. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_input_stream.rb +115 -0
  37. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras/abstract_output_stream.rb +45 -0
  38. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/ioextras.rb +38 -0
  39. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_compressor.rb +15 -0
  40. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_decompressor.rb +27 -0
  41. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/null_input_stream.rb +10 -0
  42. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/output_stream.rb +190 -0
  43. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_compressor.rb +23 -0
  44. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/pass_thru_decompressor.rb +41 -0
  45. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_directory.rb +15 -0
  46. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/streamable_stream.rb +56 -0
  47. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip/version.rb +3 -0
  48. data/lib/hotplate/gems/rubyzip-1.1.7/lib/zip.rb +63 -0
  49. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example.rb +91 -0
  50. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_filesystem.rb +33 -0
  51. data/lib/hotplate/gems/rubyzip-1.1.7/samples/example_recursive.rb +48 -0
  52. data/lib/hotplate/gems/rubyzip-1.1.7/samples/gtkRubyzip.rb +86 -0
  53. data/lib/hotplate/gems/rubyzip-1.1.7/samples/qtzip.rb +101 -0
  54. data/lib/hotplate/gems/rubyzip-1.1.7/samples/write_simple.rb +13 -0
  55. data/lib/hotplate/gems/rubyzip-1.1.7/samples/zipfind.rb +74 -0
  56. data/lib/hotplate/gems/rubyzip-1.1.7/test/basic_zip_file_test.rb +64 -0
  57. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_entry_test.rb +73 -0
  58. data/lib/hotplate/gems/rubyzip-1.1.7/test/central_directory_test.rb +104 -0
  59. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/null_encryption_test.rb +53 -0
  60. data/lib/hotplate/gems/rubyzip-1.1.7/test/crypto/traditional_encryption_test.rb +80 -0
  61. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/WarnInvalidDate.zip +0 -0
  62. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt +46 -0
  63. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file1.txt.deflatedData +0 -0
  64. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/file2.txt +1504 -0
  65. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo/bar/baz/foo.txt +0 -0
  66. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/foo.txt +0 -0
  67. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest/food.txt +0 -0
  68. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/globTest.zip +0 -0
  69. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/mimetype +1 -0
  70. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/notzippedruby.rb +7 -0
  71. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/ntfs.zip +0 -0
  72. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode.zip +0 -0
  73. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/rubycode2.zip +0 -0
  74. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/testDirectory.bin +0 -0
  75. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zip64-sample.zip +0 -0
  76. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithDirs.zip +0 -0
  77. data/lib/hotplate/gems/rubyzip-1.1.7/test/data/zipWithEncryption.zip +0 -0
  78. data/lib/hotplate/gems/rubyzip-1.1.7/test/deflater_test.rb +67 -0
  79. data/lib/hotplate/gems/rubyzip-1.1.7/test/encryption_test.rb +42 -0
  80. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_set_test.rb +138 -0
  81. data/lib/hotplate/gems/rubyzip-1.1.7/test/entry_test.rb +165 -0
  82. data/lib/hotplate/gems/rubyzip-1.1.7/test/errors_test.rb +36 -0
  83. data/lib/hotplate/gems/rubyzip-1.1.7/test/extra_field_test.rb +78 -0
  84. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_directory_test.rb +56 -0
  85. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_extract_test.rb +90 -0
  86. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_split_test.rb +60 -0
  87. data/lib/hotplate/gems/rubyzip-1.1.7/test/file_test.rb +559 -0
  88. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/dir_iterator_test.rb +62 -0
  89. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/directory_test.rb +131 -0
  90. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_mutating_test.rb +100 -0
  91. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_nonmutating_test.rb +514 -0
  92. data/lib/hotplate/gems/rubyzip-1.1.7/test/filesystem/file_stat_test.rb +66 -0
  93. data/lib/hotplate/gems/rubyzip-1.1.7/test/gentestfiles.rb +134 -0
  94. data/lib/hotplate/gems/rubyzip-1.1.7/test/inflater_test.rb +14 -0
  95. data/lib/hotplate/gems/rubyzip-1.1.7/test/input_stream_test.rb +170 -0
  96. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_input_stream_test.rb +103 -0
  97. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/abstract_output_stream_test.rb +106 -0
  98. data/lib/hotplate/gems/rubyzip-1.1.7/test/ioextras/fake_io_test.rb +18 -0
  99. data/lib/hotplate/gems/rubyzip-1.1.7/test/local_entry_test.rb +156 -0
  100. data/lib/hotplate/gems/rubyzip-1.1.7/test/output_stream_test.rb +129 -0
  101. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_compressor_test.rb +31 -0
  102. data/lib/hotplate/gems/rubyzip-1.1.7/test/pass_thru_decompressor_test.rb +15 -0
  103. data/lib/hotplate/gems/rubyzip-1.1.7/test/settings_test.rb +92 -0
  104. data/lib/hotplate/gems/rubyzip-1.1.7/test/test_helper.rb +228 -0
  105. data/lib/hotplate/gems/rubyzip-1.1.7/test/unicode_file_names_and_comments_test.rb +52 -0
  106. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_full_test.rb +53 -0
  107. data/lib/hotplate/gems/rubyzip-1.1.7/test/zip64_support_test.rb +15 -0
  108. data/lib/hotplate/java/build.gradle +38 -0
  109. data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.jar +0 -0
  110. data/lib/hotplate/java/gradle/wrapper/gradle-wrapper.properties +6 -0
  111. data/lib/hotplate/java/gradlew +164 -0
  112. data/lib/hotplate/java/gradlew.bat +90 -0
  113. data/lib/hotplate/java/template.java +25 -0
  114. data/lib/hotplate/version.rb +3 -0
  115. data/lib/hotplate.rb +2 -0
  116. metadata +186 -0
@@ -0,0 +1,514 @@
1
+ require 'test_helper'
2
+ require 'zip/filesystem'
3
+
4
+ class ZipFsFileNonmutatingTest < MiniTest::Test
5
+ def setup
6
+ @zipsha = Digest::SHA1.file("test/data/zipWithDirs.zip")
7
+ @zip_file = ::Zip::File.new("test/data/zipWithDirs.zip")
8
+ end
9
+
10
+ def teardown
11
+ @zip_file.close if @zip_file
12
+ assert_equal(@zipsha, Digest::SHA1.file("test/data/zipWithDirs.zip"))
13
+ end
14
+
15
+ def test_umask
16
+ assert_equal(::File.umask, @zip_file.file.umask)
17
+ @zip_file.file.umask(0006)
18
+ end
19
+
20
+ def test_exists?
21
+ assert(! @zip_file.file.exists?("notAFile"))
22
+ assert(@zip_file.file.exists?("file1"))
23
+ assert(@zip_file.file.exists?("dir1"))
24
+ assert(@zip_file.file.exists?("dir1/"))
25
+ assert(@zip_file.file.exists?("dir1/file12"))
26
+ assert(@zip_file.file.exist?("dir1/file12")) # notice, tests exist? alias of exists? !
27
+
28
+ @zip_file.dir.chdir "dir1/"
29
+ assert(!@zip_file.file.exists?("file1"))
30
+ assert(@zip_file.file.exists?("file12"))
31
+ end
32
+
33
+ def test_open_read
34
+ blockCalled = false
35
+ @zip_file.file.open("file1", "r") {
36
+ |f|
37
+ blockCalled = true
38
+ assert_equal("this is the entry 'file1' in my test archive!",
39
+ f.readline.chomp)
40
+ }
41
+ assert(blockCalled)
42
+
43
+ blockCalled = false
44
+ @zip_file.file.open("file1", "rb") { # test binary flag is ignored
45
+ |f|
46
+ blockCalled = true
47
+ assert_equal("this is the entry 'file1' in my test archive!",
48
+ f.readline.chomp)
49
+ }
50
+ assert(blockCalled)
51
+
52
+ blockCalled = false
53
+ @zip_file.dir.chdir "dir2"
54
+ @zip_file.file.open("file21", "r") {
55
+ |f|
56
+ blockCalled = true
57
+ assert_equal("this is the entry 'dir2/file21' in my test archive!",
58
+ f.readline.chomp)
59
+ }
60
+ assert(blockCalled)
61
+ @zip_file.dir.chdir "/"
62
+
63
+ assert_raises(Errno::ENOENT) {
64
+ @zip_file.file.open("noSuchEntry")
65
+ }
66
+
67
+ begin
68
+ is = @zip_file.file.open("file1")
69
+ assert_equal("this is the entry 'file1' in my test archive!",
70
+ is.readline.chomp)
71
+ ensure
72
+ is.close if is
73
+ end
74
+ end
75
+
76
+ def test_new
77
+ begin
78
+ is = @zip_file.file.new("file1")
79
+ assert_equal("this is the entry 'file1' in my test archive!",
80
+ is.readline.chomp)
81
+ ensure
82
+ is.close if is
83
+ end
84
+ begin
85
+ is = @zip_file.file.new("file1") {
86
+ fail "should not call block"
87
+ }
88
+ ensure
89
+ is.close if is
90
+ end
91
+ end
92
+
93
+ def test_symlink
94
+ assert_raises(NotImplementedError) {
95
+ @zip_file.file.symlink("file1", "aSymlink")
96
+ }
97
+ end
98
+
99
+ def test_size
100
+ assert_raises(Errno::ENOENT) { @zip_file.file.size("notAFile") }
101
+ assert_equal(72, @zip_file.file.size("file1"))
102
+ assert_equal(0, @zip_file.file.size("dir2/dir21"))
103
+
104
+ assert_equal(72, @zip_file.file.stat("file1").size)
105
+ assert_equal(0, @zip_file.file.stat("dir2/dir21").size)
106
+ end
107
+
108
+ def test_size?
109
+ assert_equal(nil, @zip_file.file.size?("notAFile"))
110
+ assert_equal(72, @zip_file.file.size?("file1"))
111
+ assert_equal(nil, @zip_file.file.size?("dir2/dir21"))
112
+
113
+ assert_equal(72, @zip_file.file.stat("file1").size?)
114
+ assert_equal(nil, @zip_file.file.stat("dir2/dir21").size?)
115
+ end
116
+
117
+
118
+ def test_file?
119
+ assert(@zip_file.file.file?("file1"))
120
+ assert(@zip_file.file.file?("dir2/file21"))
121
+ assert(! @zip_file.file.file?("dir1"))
122
+ assert(! @zip_file.file.file?("dir1/dir11"))
123
+
124
+ assert(@zip_file.file.stat("file1").file?)
125
+ assert(@zip_file.file.stat("dir2/file21").file?)
126
+ assert(! @zip_file.file.stat("dir1").file?)
127
+ assert(! @zip_file.file.stat("dir1/dir11").file?)
128
+ end
129
+
130
+ include ExtraAssertions
131
+
132
+ def test_dirname
133
+ assert_forwarded(File, :dirname, "retVal", "a/b/c/d") {
134
+ @zip_file.file.dirname("a/b/c/d")
135
+ }
136
+ end
137
+
138
+ def test_basename
139
+ assert_forwarded(File, :basename, "retVal", "a/b/c/d") {
140
+ @zip_file.file.basename("a/b/c/d")
141
+ }
142
+ end
143
+
144
+ def test_split
145
+ assert_forwarded(File, :split, "retVal", "a/b/c/d") {
146
+ @zip_file.file.split("a/b/c/d")
147
+ }
148
+ end
149
+
150
+ def test_join
151
+ assert_equal("a/b/c", @zip_file.file.join("a/b", "c"))
152
+ assert_equal("a/b/c/d", @zip_file.file.join("a/b", "c/d"))
153
+ assert_equal("/c/d", @zip_file.file.join("", "c/d"))
154
+ assert_equal("a/b/c/d", @zip_file.file.join("a", "b", "c", "d"))
155
+ end
156
+
157
+ def test_utime
158
+ t_now = ::Zip::DOSTime.now
159
+ t_bak = @zip_file.file.mtime("file1")
160
+ @zip_file.file.utime(t_now, "file1")
161
+ assert_equal(t_now, @zip_file.file.mtime("file1"))
162
+ @zip_file.file.utime(t_bak, "file1")
163
+ assert_equal(t_bak, @zip_file.file.mtime("file1"))
164
+ end
165
+
166
+
167
+ def assert_always_false(operation)
168
+ assert(! @zip_file.file.send(operation, "noSuchFile"))
169
+ assert(! @zip_file.file.send(operation, "file1"))
170
+ assert(! @zip_file.file.send(operation, "dir1"))
171
+ assert(! @zip_file.file.stat("file1").send(operation))
172
+ assert(! @zip_file.file.stat("dir1").send(operation))
173
+ end
174
+
175
+ def assert_true_if_entry_exists(operation)
176
+ assert(! @zip_file.file.send(operation, "noSuchFile"))
177
+ assert(@zip_file.file.send(operation, "file1"))
178
+ assert(@zip_file.file.send(operation, "dir1"))
179
+ assert(@zip_file.file.stat("file1").send(operation))
180
+ assert(@zip_file.file.stat("dir1").send(operation))
181
+ end
182
+
183
+ def test_pipe?
184
+ assert_always_false(:pipe?)
185
+ end
186
+
187
+ def test_blockdev?
188
+ assert_always_false(:blockdev?)
189
+ end
190
+
191
+ def test_symlink?
192
+ assert_always_false(:symlink?)
193
+ end
194
+
195
+ def test_socket?
196
+ assert_always_false(:socket?)
197
+ end
198
+
199
+ def test_chardev?
200
+ assert_always_false(:chardev?)
201
+ end
202
+
203
+ def test_truncate
204
+ assert_raises(StandardError, "truncate not supported") {
205
+ @zip_file.file.truncate("file1", 100)
206
+ }
207
+ end
208
+
209
+ def assert_e_n_o_e_n_t(operation, args = ["NoSuchFile"])
210
+ assert_raises(Errno::ENOENT) {
211
+ @zip_file.file.send(operation, *args)
212
+ }
213
+ end
214
+
215
+ def test_ftype
216
+ assert_e_n_o_e_n_t(:ftype)
217
+ assert_equal("file", @zip_file.file.ftype("file1"))
218
+ assert_equal("directory", @zip_file.file.ftype("dir1/dir11"))
219
+ assert_equal("directory", @zip_file.file.ftype("dir1/dir11/"))
220
+ end
221
+
222
+ def test_link
223
+ assert_raises(NotImplementedError) {
224
+ @zip_file.file.link("file1", "someOtherString")
225
+ }
226
+ end
227
+
228
+ def test_directory?
229
+ assert(! @zip_file.file.directory?("notAFile"))
230
+ assert(! @zip_file.file.directory?("file1"))
231
+ assert(! @zip_file.file.directory?("dir1/file11"))
232
+ assert(@zip_file.file.directory?("dir1"))
233
+ assert(@zip_file.file.directory?("dir1/"))
234
+ assert(@zip_file.file.directory?("dir2/dir21"))
235
+
236
+ assert(! @zip_file.file.stat("file1").directory?)
237
+ assert(! @zip_file.file.stat("dir1/file11").directory?)
238
+ assert(@zip_file.file.stat("dir1").directory?)
239
+ assert(@zip_file.file.stat("dir1/").directory?)
240
+ assert(@zip_file.file.stat("dir2/dir21").directory?)
241
+ end
242
+
243
+ def test_chown
244
+ assert_equal(2, @zip_file.file.chown(1,2, "dir1", "file1"))
245
+ assert_equal(1, @zip_file.file.stat("dir1").uid)
246
+ assert_equal(2, @zip_file.file.stat("dir1").gid)
247
+ assert_equal(2, @zip_file.file.chown(nil, nil, "dir1", "file1"))
248
+ end
249
+
250
+ def test_zero?
251
+ assert(! @zip_file.file.zero?("notAFile"))
252
+ assert(! @zip_file.file.zero?("file1"))
253
+ assert(@zip_file.file.zero?("dir1"))
254
+ blockCalled = false
255
+ ::Zip::File.open("test/data/generated/5entry.zip") {
256
+ |zf|
257
+ blockCalled = true
258
+ assert(zf.file.zero?("test/data/generated/empty.txt"))
259
+ }
260
+ assert(blockCalled)
261
+
262
+ assert(! @zip_file.file.stat("file1").zero?)
263
+ assert(@zip_file.file.stat("dir1").zero?)
264
+ blockCalled = false
265
+ ::Zip::File.open("test/data/generated/5entry.zip") {
266
+ |zf|
267
+ blockCalled = true
268
+ assert(zf.file.stat("test/data/generated/empty.txt").zero?)
269
+ }
270
+ assert(blockCalled)
271
+ end
272
+
273
+ def test_expand_path
274
+ ::Zip::File.open("test/data/zipWithDirs.zip") {
275
+ |zf|
276
+ assert_equal("/", zf.file.expand_path("."))
277
+ zf.dir.chdir "dir1"
278
+ assert_equal("/dir1", zf.file.expand_path("."))
279
+ assert_equal("/dir1/file12", zf.file.expand_path("file12"))
280
+ assert_equal("/", zf.file.expand_path(".."))
281
+ assert_equal("/dir2/dir21", zf.file.expand_path("../dir2/dir21"))
282
+ }
283
+ end
284
+
285
+ def test_mtime
286
+ assert_equal(::Zip::DOSTime.at(1027694306),
287
+ @zip_file.file.mtime("dir2/file21"))
288
+ assert_equal(::Zip::DOSTime.at(1027690863),
289
+ @zip_file.file.mtime("dir2/dir21"))
290
+ assert_raises(Errno::ENOENT) {
291
+ @zip_file.file.mtime("noSuchEntry")
292
+ }
293
+
294
+ assert_equal(::Zip::DOSTime.at(1027694306),
295
+ @zip_file.file.stat("dir2/file21").mtime)
296
+ assert_equal(::Zip::DOSTime.at(1027690863),
297
+ @zip_file.file.stat("dir2/dir21").mtime)
298
+ end
299
+
300
+ def test_ctime
301
+ assert_nil(@zip_file.file.ctime("file1"))
302
+ assert_nil(@zip_file.file.stat("file1").ctime)
303
+ end
304
+
305
+ def test_atime
306
+ assert_nil(@zip_file.file.atime("file1"))
307
+ assert_nil(@zip_file.file.stat("file1").atime)
308
+ end
309
+
310
+ def test_ntfs_time
311
+ ::Zip::File.open("test/data/ntfs.zip") do |zf|
312
+ t = ::Zip::DOSTime.at(1410496497.405178)
313
+ assert_equal(zf.file.mtime("data.txt"), t)
314
+ assert_equal(zf.file.atime("data.txt"), t)
315
+ assert_equal(zf.file.ctime("data.txt"), t)
316
+ end
317
+ end
318
+
319
+ def test_readable?
320
+ assert(! @zip_file.file.readable?("noSuchFile"))
321
+ assert(@zip_file.file.readable?("file1"))
322
+ assert(@zip_file.file.readable?("dir1"))
323
+ assert(@zip_file.file.stat("file1").readable?)
324
+ assert(@zip_file.file.stat("dir1").readable?)
325
+ end
326
+
327
+ def test_readable_real?
328
+ assert(! @zip_file.file.readable_real?("noSuchFile"))
329
+ assert(@zip_file.file.readable_real?("file1"))
330
+ assert(@zip_file.file.readable_real?("dir1"))
331
+ assert(@zip_file.file.stat("file1").readable_real?)
332
+ assert(@zip_file.file.stat("dir1").readable_real?)
333
+ end
334
+
335
+ def test_writable?
336
+ assert(! @zip_file.file.writable?("noSuchFile"))
337
+ assert(@zip_file.file.writable?("file1"))
338
+ assert(@zip_file.file.writable?("dir1"))
339
+ assert(@zip_file.file.stat("file1").writable?)
340
+ assert(@zip_file.file.stat("dir1").writable?)
341
+ end
342
+
343
+ def test_writable_real?
344
+ assert(! @zip_file.file.writable_real?("noSuchFile"))
345
+ assert(@zip_file.file.writable_real?("file1"))
346
+ assert(@zip_file.file.writable_real?("dir1"))
347
+ assert(@zip_file.file.stat("file1").writable_real?)
348
+ assert(@zip_file.file.stat("dir1").writable_real?)
349
+ end
350
+
351
+ def test_executable?
352
+ assert(! @zip_file.file.executable?("noSuchFile"))
353
+ assert(! @zip_file.file.executable?("file1"))
354
+ assert(@zip_file.file.executable?("dir1"))
355
+ assert(! @zip_file.file.stat("file1").executable?)
356
+ assert(@zip_file.file.stat("dir1").executable?)
357
+ end
358
+
359
+ def test_executable_real?
360
+ assert(! @zip_file.file.executable_real?("noSuchFile"))
361
+ assert(! @zip_file.file.executable_real?("file1"))
362
+ assert(@zip_file.file.executable_real?("dir1"))
363
+ assert(! @zip_file.file.stat("file1").executable_real?)
364
+ assert(@zip_file.file.stat("dir1").executable_real?)
365
+ end
366
+
367
+ def test_owned?
368
+ assert_true_if_entry_exists(:owned?)
369
+ end
370
+
371
+ def test_grpowned?
372
+ assert_true_if_entry_exists(:grpowned?)
373
+ end
374
+
375
+ def test_setgid?
376
+ assert_always_false(:setgid?)
377
+ end
378
+
379
+ def test_setuid?
380
+ assert_always_false(:setgid?)
381
+ end
382
+
383
+ def test_sticky?
384
+ assert_always_false(:sticky?)
385
+ end
386
+
387
+ def test_readlink
388
+ assert_raises(NotImplementedError) {
389
+ @zip_file.file.readlink("someString")
390
+ }
391
+ end
392
+
393
+ def test_stat
394
+ s = @zip_file.file.stat("file1")
395
+ assert(s.kind_of?(File::Stat)) # It pretends
396
+ assert_raises(Errno::ENOENT, "No such file or directory - noSuchFile") {
397
+ @zip_file.file.stat("noSuchFile")
398
+ }
399
+ end
400
+
401
+ def test_lstat
402
+ assert(@zip_file.file.lstat("file1").file?)
403
+ end
404
+
405
+ def test_pipe
406
+ assert_raises(NotImplementedError) {
407
+ @zip_file.file.pipe
408
+ }
409
+ end
410
+
411
+ def test_foreach
412
+ ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
413
+ ref = []
414
+ File.foreach("test/data/file1.txt") { |e| ref << e }
415
+ index = 0
416
+
417
+ zf.file.foreach("test/data/file1.txt") do |l|
418
+ #Ruby replaces \n with \r\n automatically on windows
419
+ newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
420
+ assert_equal(ref[index], newline)
421
+ index = index.next
422
+ end
423
+ assert_equal(ref.size, index)
424
+ end
425
+
426
+ ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
427
+ ref = []
428
+ File.foreach("test/data/file1.txt", " ") { |e| ref << e }
429
+ index = 0
430
+
431
+ zf.file.foreach("test/data/file1.txt", " ") do |l|
432
+ #Ruby replaces \n with \r\n automatically on windows
433
+ newline = Zip::RUNNING_ON_WINDOWS ? l.gsub(/\r\n/, "\n") : l
434
+ assert_equal(ref[index], newline)
435
+ index = index.next
436
+ end
437
+ assert_equal(ref.size, index)
438
+ end
439
+ end
440
+
441
+ def test_glob
442
+ ::Zip::File.open('test/data/globTest.zip') do |zf|
443
+ {
444
+ 'globTest/foo.txt' => ['globTest/foo.txt'],
445
+ '*/foo.txt' => ['globTest/foo.txt'],
446
+ '**/foo.txt' => ['globTest/foo.txt','globTest/foo/bar/baz/foo.txt'],
447
+ '*/foo/**/*.txt' => ['globTest/foo/bar/baz/foo.txt']
448
+ }.each do |spec,expected_results|
449
+ results = zf.glob(spec)
450
+ assert results.all?{|entry| entry.is_a? ::Zip::Entry }
451
+
452
+ result_strings = results.map(&:to_s)
453
+ missing_matches = expected_results - result_strings
454
+ extra_matches = result_strings - expected_results
455
+
456
+ assert extra_matches.empty?, %Q{spec #{spec.inspect} has extra results #{extra_matches.inspect}}
457
+ assert missing_matches.empty?, %Q{spec #{spec.inspect} missing results #{missing_matches.inspect}}
458
+ end
459
+ end
460
+
461
+ ::Zip::File.open('test/data/globTest.zip') do |zf|
462
+ results = []
463
+ zf.glob('**/foo.txt') do |match|
464
+ results << "<#{match.class.name}: #{match.to_s}>"
465
+ end
466
+ assert((not results.empty?), 'block not run, or run out of context')
467
+ assert_equal 2, results.size
468
+ assert_operator results, :include?, '<Zip::Entry: globTest/foo.txt>'
469
+ assert_operator results, :include?, '<Zip::Entry: globTest/foo/bar/baz/foo.txt>'
470
+ end
471
+ end
472
+
473
+ def test_popen
474
+ if Zip::RUNNING_ON_WINDOWS
475
+ #This is pretty much projectile vomit but it allows the test to be
476
+ #run on windows also
477
+ system_dir = ::File.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '')
478
+ zipfile_dir = @zip_file.file.popen('dir') { |f| f.read }.gsub(/Dir\(s\).*$/, '')
479
+ assert_equal(system_dir, zipfile_dir)
480
+ else
481
+ assert_equal(::File.popen('ls') { |f| f.read },
482
+ @zip_file.file.popen('ls') { |f| f.read })
483
+ end
484
+ end
485
+
486
+ # Can be added later
487
+ # def test_select
488
+ # fail "implement test"
489
+ # end
490
+
491
+ def test_readlines
492
+ ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
493
+ orig_file = ::File.readlines("test/data/file1.txt")
494
+ zip_file = zf.file.readlines("test/data/file1.txt")
495
+
496
+ #Ruby replaces \n with \r\n automatically on windows
497
+ zip_file.each { |l| l.gsub!(/\r\n/, "\n") } if Zip::RUNNING_ON_WINDOWS
498
+
499
+ assert_equal(orig_file, zip_file)
500
+ end
501
+ end
502
+
503
+ def test_read
504
+ ::Zip::File.open("test/data/generated/zipWithDir.zip") do |zf|
505
+ orig_file = ::File.read("test/data/file1.txt")
506
+
507
+ #Ruby replaces \n with \r\n automatically on windows
508
+ zip_file = Zip::RUNNING_ON_WINDOWS ? \
509
+ zf.file.read("test/data/file1.txt").gsub(/\r\n/, "\n") : zf.file.read("test/data/file1.txt")
510
+ assert_equal(orig_file, zip_file)
511
+ end
512
+ end
513
+
514
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+ require 'zip/filesystem'
3
+
4
+ class ZipFsFileStatTest < MiniTest::Test
5
+
6
+ def setup
7
+ @zip_file = ::Zip::File.new("test/data/zipWithDirs.zip")
8
+ end
9
+
10
+ def teardown
11
+ @zip_file.close if @zip_file
12
+ end
13
+
14
+ def test_blocks
15
+ assert_equal(nil, @zip_file.file.stat("file1").blocks)
16
+ end
17
+
18
+ def test_ino
19
+ assert_equal(0, @zip_file.file.stat("file1").ino)
20
+ end
21
+
22
+ def test_uid
23
+ assert_equal(0, @zip_file.file.stat("file1").uid)
24
+ end
25
+
26
+ def test_gid
27
+ assert_equal(0, @zip_file.file.stat("file1").gid)
28
+ end
29
+
30
+ def test_ftype
31
+ assert_equal("file", @zip_file.file.stat("file1").ftype)
32
+ assert_equal("directory", @zip_file.file.stat("dir1").ftype)
33
+ end
34
+
35
+ def test_mode
36
+ assert_equal(0600, @zip_file.file.stat("file1").mode & 0777)
37
+ assert_equal(0600, @zip_file.file.stat("file1").mode & 0777)
38
+ assert_equal(0755, @zip_file.file.stat("dir1").mode & 0777)
39
+ assert_equal(0755, @zip_file.file.stat("dir1").mode & 0777)
40
+ end
41
+
42
+ def test_dev
43
+ assert_equal(0, @zip_file.file.stat("file1").dev)
44
+ end
45
+
46
+ def test_rdev
47
+ assert_equal(0, @zip_file.file.stat("file1").rdev)
48
+ end
49
+
50
+ def test_rdev_major
51
+ assert_equal(0, @zip_file.file.stat("file1").rdev_major)
52
+ end
53
+
54
+ def test_rdev_minor
55
+ assert_equal(0, @zip_file.file.stat("file1").rdev_minor)
56
+ end
57
+
58
+ def test_nlink
59
+ assert_equal(1, @zip_file.file.stat("file1").nlink)
60
+ end
61
+
62
+ def test_blksize
63
+ assert_nil(@zip_file.file.stat("file1").blksize)
64
+ end
65
+
66
+ end