build-files 1.6.0 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/lib/build/files/path.rb +29 -0
- data/lib/build/files/state.rb +23 -23
- data/lib/build/files/version.rb +1 -1
- data/lib/build/files.rb +0 -3
- data.tar.gz.sig +0 -0
- metadata +43 -91
- metadata.gz.sig +0 -0
- data/.gitignore +0 -24
- data/.rspec +0 -4
- data/.travis.yml +0 -14
- data/Gemfile +0 -9
- data/README.md +0 -69
- data/build-files.gemspec +0 -28
- data/lib/build/files/handle.rb +0 -59
- data/lib/build/files/monitor/fsevent.rb +0 -55
- data/lib/build/files/monitor/inotify.rb +0 -53
- data/lib/build/files/monitor/polling.rb +0 -145
- data/lib/build/files/monitor.rb +0 -43
- data/spec/build/files/directory_spec/.dot_file.yaml +0 -0
- data/spec/build/files/directory_spec/normal_file.txt +0 -0
- data/spec/build/files/directory_spec.rb +0 -80
- data/spec/build/files/glob_spec/dotfiles/.file +0 -0
- data/spec/build/files/glob_spec.rb +0 -53
- data/spec/build/files/list_spec.rb +0 -182
- data/spec/build/files/monitor_spec.rb +0 -90
- data/spec/build/files/path_spec.rb +0 -211
- data/spec/build/files/state_spec.rb +0 -90
- data/spec/build/files/system_spec.rb +0 -56
- data/spec/spec_helper.rb +0 -11
@@ -1,211 +0,0 @@
|
|
1
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'build/files'
|
22
|
-
require 'build/files/path'
|
23
|
-
|
24
|
-
require 'pathname'
|
25
|
-
|
26
|
-
RSpec.describe Build::Files::Path do
|
27
|
-
it "should expand the path" do
|
28
|
-
expect(Build::Files::Path.expand("foo", "/bar")).to be == "/bar/foo"
|
29
|
-
end
|
30
|
-
|
31
|
-
it "should give current path" do
|
32
|
-
path = Build::Files::Path.new("/a/b/c/file.cpp")
|
33
|
-
|
34
|
-
expect(path.shortest_path(path)).to be == "."
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should give the shortest path for outer paths" do
|
38
|
-
input = Build::Files::Path.new("/a/b/c/file.cpp")
|
39
|
-
output = Build::Files::Path.new("/a/b/c/d/e/")
|
40
|
-
|
41
|
-
expect(input.root).to be == "/a/b/c"
|
42
|
-
expect(output.root).to be == "/a/b/c/d/e"
|
43
|
-
|
44
|
-
short = input.shortest_path(output)
|
45
|
-
|
46
|
-
expect(short).to be == "../../file.cpp"
|
47
|
-
|
48
|
-
expect(File.expand_path(short, output)).to be == input
|
49
|
-
end
|
50
|
-
|
51
|
-
it "should give the shortest path for inner paths" do
|
52
|
-
input = Build::Files::Path.new("/a/b/c/file.cpp")
|
53
|
-
output = Build::Files::Path.new("/a/")
|
54
|
-
|
55
|
-
expect(input.root).to be == "/a/b/c"
|
56
|
-
expect(output.root).to be == "/a"
|
57
|
-
|
58
|
-
short = input.shortest_path(output)
|
59
|
-
|
60
|
-
expect(short).to be == "b/c/file.cpp"
|
61
|
-
|
62
|
-
expect(File.expand_path(short, output)).to be == input
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
RSpec.describe Build::Files::Path.new("/test") do
|
67
|
-
it "should start_with? full path" do
|
68
|
-
expect(subject).to be_start_with '/test'
|
69
|
-
end
|
70
|
-
|
71
|
-
it "should start_with? partial pattern" do
|
72
|
-
expect(subject).to be_start_with '/te'
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
RSpec.describe Build::Files::Path.new("/foo/bar.txt") do
|
77
|
-
it "should replace existing file extension" do
|
78
|
-
expect(subject.with(extension: '.jpeg', basename: true)).to be == "/foo/bar.jpeg"
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should append file extension" do
|
82
|
-
expect(subject.with(extension: '.jpeg')).to be == "/foo/bar.txt.jpeg"
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should change basename" do
|
86
|
-
expect(subject.with(basename: 'baz', extension: '.txt')).to be == "/foo/baz.txt"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
RSpec.describe Build::Files::Path.new("/foo/bar/baz", "/foo") do
|
91
|
-
it "can add nil path" do
|
92
|
-
expect(subject + nil).to be == subject
|
93
|
-
end
|
94
|
-
|
95
|
-
it "can inspect path with nil root" do
|
96
|
-
expect do
|
97
|
-
(subject / nil).inspect
|
98
|
-
end.to_not raise_error
|
99
|
-
end
|
100
|
-
|
101
|
-
it "can add nil root" do
|
102
|
-
expect(subject / nil).to be == subject
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should be inspectable" do
|
106
|
-
expect(subject.inspect).to be_include subject.root.to_s
|
107
|
-
expect(subject.inspect).to be_include subject.relative_path.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
it "should convert to path" do
|
111
|
-
pathname = Pathname("/foo/bar/baz")
|
112
|
-
|
113
|
-
expect(Build::Files::Path[pathname]).to be == subject
|
114
|
-
expect(Build::Files::Path["/foo/bar/baz"]).to be == subject
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should be equal" do
|
118
|
-
expect(subject).to be_eql subject
|
119
|
-
expect(subject).to be == subject
|
120
|
-
|
121
|
-
different_root_path = Build::Files::Path.join("/foo/bar", "baz")
|
122
|
-
expect(subject).to_not be_eql different_root_path
|
123
|
-
expect(subject).to be == different_root_path
|
124
|
-
end
|
125
|
-
|
126
|
-
it "should convert to string" do
|
127
|
-
expect(subject.to_s).to be == "/foo/bar/baz"
|
128
|
-
|
129
|
-
# The to_str method should return the full path (i.e. the same as to_s):
|
130
|
-
expect(subject.to_s).to be == subject.to_str
|
131
|
-
|
132
|
-
# Check the equality operator:
|
133
|
-
expect(subject).to be == subject.dup
|
134
|
-
|
135
|
-
# The length should be reported correctly:
|
136
|
-
expect(subject.length).to be == subject.to_s.length
|
137
|
-
|
138
|
-
# Check the return types:
|
139
|
-
expect(subject).to be_kind_of Build::Files::Path
|
140
|
-
expect(subject.root).to be_kind_of String
|
141
|
-
expect(subject.relative_path).to be_kind_of String
|
142
|
-
end
|
143
|
-
|
144
|
-
it "should consist of parts" do
|
145
|
-
expect(subject.parts).to be == ["", "foo", "bar", "baz"]
|
146
|
-
|
147
|
-
expect(subject.root).to be == "/foo"
|
148
|
-
|
149
|
-
expect(subject.relative_path).to be == "bar/baz"
|
150
|
-
|
151
|
-
expect(subject.relative_parts).to be == ["bar", "baz"]
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should have a new extension" do
|
155
|
-
renamed_path = subject.with(root: '/tmp', extension: '.txt')
|
156
|
-
|
157
|
-
expect(renamed_path.root).to be == '/tmp'
|
158
|
-
|
159
|
-
expect(renamed_path.relative_path).to be == 'bar/baz.txt'
|
160
|
-
|
161
|
-
object_path = subject.append(".o")
|
162
|
-
|
163
|
-
expect(object_path.root).to be == "/foo"
|
164
|
-
expect(object_path.relative_path).to be == "bar/baz.o"
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should append a path" do
|
168
|
-
subject = Build::Files::Path.new("/a/b/c")
|
169
|
-
|
170
|
-
expect(subject + "d/e/f").to be == "/a/b/c/d/e/f"
|
171
|
-
end
|
172
|
-
|
173
|
-
it "should give a list of components" do
|
174
|
-
expect(Build::Files::Path.components(subject)).to be == ["", "foo", "bar", "baz"]
|
175
|
-
expect(Build::Files::Path.components(subject.to_s)).to be == ["", "foo", "bar", "baz"]
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should give a basename" do
|
179
|
-
expect(subject.basename).to be == "baz"
|
180
|
-
end
|
181
|
-
|
182
|
-
it "should have a new root" do
|
183
|
-
rerooted_path = subject / "cat"
|
184
|
-
|
185
|
-
expect(rerooted_path.root).to be == "/foo/bar/baz"
|
186
|
-
expect(rerooted_path.relative_path).to be == "cat"
|
187
|
-
end
|
188
|
-
|
189
|
-
it "should give correct modes for reading" do
|
190
|
-
expect(subject.for_reading).to be == [subject.to_s, File::RDONLY]
|
191
|
-
end
|
192
|
-
|
193
|
-
it "should give correct modes for writing" do
|
194
|
-
expect(subject.for_writing).to be == [subject.to_s, File::CREAT|File::TRUNC|File::WRONLY]
|
195
|
-
end
|
196
|
-
|
197
|
-
it "should give correct modes for appending" do
|
198
|
-
expect(subject.for_appending).to be == [subject.to_s, File::CREAT|File::APPEND|File::WRONLY]
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should match against relative path" do
|
202
|
-
expect(subject.match(subject.relative_path)).to be_truthy
|
203
|
-
expect(subject.match("*/baz")).to be_truthy
|
204
|
-
expect(subject.match("/baz")).to be_falsey
|
205
|
-
end
|
206
|
-
|
207
|
-
it "should match against absolute path" do
|
208
|
-
expect(subject.match(subject.to_s)).to be_truthy
|
209
|
-
expect(subject.match("/foo/**")).to be_truthy
|
210
|
-
end
|
211
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'build/files'
|
22
|
-
|
23
|
-
module Build::Files::StateSpec
|
24
|
-
describe Build::Files::State do
|
25
|
-
let(:files) {Build::Files::Glob.new(__dir__, "*.rb")}
|
26
|
-
|
27
|
-
it "should have no changes initially" do
|
28
|
-
state = Build::Files::State.new(files)
|
29
|
-
|
30
|
-
expect(state.update!).to be false
|
31
|
-
|
32
|
-
expect(state.changed).to be == []
|
33
|
-
expect(state.added).to be == []
|
34
|
-
expect(state.removed).to be == []
|
35
|
-
expect(state.missing).to be == []
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should report missing files" do
|
39
|
-
rebased_files = files.to_paths.rebase(File.join(__dir__, 'foo'))
|
40
|
-
state = Build::Files::State.new(rebased_files)
|
41
|
-
|
42
|
-
# Some changes were detected:
|
43
|
-
expect(state.update!).to be true
|
44
|
-
|
45
|
-
# Some files are missing:
|
46
|
-
expect(state.missing).to_not be_empty
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should not be confused by duplicates" do
|
50
|
-
state = Build::Files::State.new(files + files)
|
51
|
-
|
52
|
-
expect(state.update!).to be false
|
53
|
-
|
54
|
-
expect(state.changed).to be == []
|
55
|
-
expect(state.added).to be == []
|
56
|
-
expect(state.removed).to be == []
|
57
|
-
expect(state.missing).to be == []
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
describe Build::Files::State do
|
62
|
-
before(:each) do
|
63
|
-
@temporary_files = Build::Files::Paths.directory(__dir__, ['a'])
|
64
|
-
@temporary_files.touch
|
65
|
-
|
66
|
-
@new_files = Build::Files::State.new(@temporary_files)
|
67
|
-
@old_files = Build::Files::State.new(Build::Files::Glob.new(__dir__, "*.rb"))
|
68
|
-
end
|
69
|
-
|
70
|
-
after(:each) do
|
71
|
-
@temporary_files.delete
|
72
|
-
end
|
73
|
-
|
74
|
-
let(:empty) {Build::Files::State.new(Build::Files::List::NONE)}
|
75
|
-
|
76
|
-
it "should be clean with empty inputs or outputs" do
|
77
|
-
expect(Build::Files::State.dirty?(empty, @new_files)).to be false
|
78
|
-
expect(Build::Files::State.dirty?(@new_files, empty)).to be false
|
79
|
-
end
|
80
|
-
|
81
|
-
it "should be clean if files are newer" do
|
82
|
-
expect(Build::Files::State.dirty?(@old_files, @new_files)).to be false
|
83
|
-
end
|
84
|
-
|
85
|
-
it "should be dirty if files are modified" do
|
86
|
-
# In this case, the file mtime is usually different so...
|
87
|
-
expect(Build::Files::State.dirty?(@new_files, @old_files)).to be true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# Copyright, 2012, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
2
|
-
#
|
3
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
-
# of this software and associated documentation files (the "Software"), to deal
|
5
|
-
# in the Software without restriction, including without limitation the rights
|
6
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
-
# copies of the Software, and to permit persons to whom the Software is
|
8
|
-
# furnished to do so, subject to the following conditions:
|
9
|
-
#
|
10
|
-
# The above copyright notice and this permission notice shall be included in
|
11
|
-
# all copies or substantial portions of the Software.
|
12
|
-
#
|
13
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
-
# THE SOFTWARE.
|
20
|
-
|
21
|
-
require 'build/files'
|
22
|
-
require 'build/files/path'
|
23
|
-
require 'build/files/system'
|
24
|
-
|
25
|
-
require 'pathname'
|
26
|
-
|
27
|
-
module Build::Files::FilesystemSpec
|
28
|
-
include Build::Files
|
29
|
-
|
30
|
-
describe Build::Files::Path do
|
31
|
-
let(:root) {Path.new(__dir__)}
|
32
|
-
let(:path) {root + "filesystem_spec"}
|
33
|
-
|
34
|
-
after(:each) do
|
35
|
-
path.delete
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should open file for writing" do
|
39
|
-
path.write("Hello World")
|
40
|
-
|
41
|
-
expect(File).to be_exist(path)
|
42
|
-
expect(path.read).to be == "Hello World"
|
43
|
-
|
44
|
-
expect(path).to be_exist
|
45
|
-
expect(path.directory?).to be == false
|
46
|
-
|
47
|
-
expect(path.modified_time.to_f).to be_within(5.0).of(Time.now.to_f)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should make a directory" do
|
51
|
-
path.create
|
52
|
-
|
53
|
-
expect(path.directory?).to be == true
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
data/spec/spec_helper.rb
DELETED