build-files 1.4.3 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/.DS_Store +0 -0
- data/lib/build/files.rb +0 -3
- data/lib/build/files/.DS_Store +0 -0
- data/lib/build/files/glob.rb +9 -6
- data/lib/build/files/list.rb +4 -4
- data/lib/build/files/path.rb +38 -11
- data/lib/build/files/paths.rb +6 -0
- data/lib/build/files/version.rb +1 -1
- metadata +14 -88
- data/.rspec +0 -4
- data/.travis.yml +0 -14
- data/Gemfile +0 -9
- data/README.md +0 -69
- data/Rakefile +0 -6
- data/build-files.gemspec +0 -28
- data/lib/build/files/handle.rb +0 -59
- data/lib/build/files/monitor.rb +0 -43
- 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/state.rb +0 -172
- data/spec/build/files/directory_spec.rb +0 -80
- 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/glob_spec.rb +0 -49
- 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 -205
- 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,80 +0,0 @@
|
|
1
|
-
# Copyright, 2014, 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/directory'
|
22
|
-
|
23
|
-
module Build::Files::DirectorySpec
|
24
|
-
include Build::Files
|
25
|
-
|
26
|
-
describe Build::Files::Directory do
|
27
|
-
let(:path) {Path.new("/foo/bar/baz", "/foo")}
|
28
|
-
let(:directory) {Directory.new(path)}
|
29
|
-
|
30
|
-
it "can be constructed using join" do
|
31
|
-
joined_directory = Directory.join('/foo', 'bar/baz')
|
32
|
-
|
33
|
-
expect(joined_directory).to be == directory
|
34
|
-
end
|
35
|
-
|
36
|
-
it "has a root and path component" do
|
37
|
-
expect(directory.root).to be == path
|
38
|
-
expect(directory.to_path).to be == path
|
39
|
-
|
40
|
-
expect(directory.roots).to be_include(path)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "can be converted into a string" do
|
44
|
-
expect(directory.to_str).to be == path.to_str
|
45
|
-
end
|
46
|
-
|
47
|
-
it "can be used as a key" do
|
48
|
-
hash = {directory => true}
|
49
|
-
|
50
|
-
expect(hash).to be_include directory
|
51
|
-
end
|
52
|
-
|
53
|
-
it "includes subpaths" do
|
54
|
-
expect(directory).to be_include "/foo/bar/baz/bob/dole"
|
55
|
-
end
|
56
|
-
|
57
|
-
it "can be compared" do
|
58
|
-
other_directory = Directory.new(path + 'dole')
|
59
|
-
|
60
|
-
expect(directory).to be_eql directory
|
61
|
-
expect(directory).to_not be_eql other_directory
|
62
|
-
end
|
63
|
-
|
64
|
-
it "can be rebased" do
|
65
|
-
rebased_directory = directory.rebase("/fu")
|
66
|
-
|
67
|
-
expect(rebased_directory.root).to be == '/fu/bar/baz'
|
68
|
-
end
|
69
|
-
|
70
|
-
context Directory.join(__dir__, "directory_spec") do
|
71
|
-
it "can list dot files" do
|
72
|
-
expect(subject).to include(subject.root + '.dot_file.yaml')
|
73
|
-
end
|
74
|
-
|
75
|
-
it "can list normal files" do
|
76
|
-
expect(subject).to include(subject.root + 'normal_file.txt')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
File without changes
|
File without changes
|
@@ -1,49 +0,0 @@
|
|
1
|
-
# Copyright, 2014, 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/glob'
|
22
|
-
|
23
|
-
module Build::Files::GlobSpec
|
24
|
-
include Build::Files
|
25
|
-
|
26
|
-
describe Build::Files::Glob do
|
27
|
-
let(:path) {Path.new(__dir__)}
|
28
|
-
|
29
|
-
it "can glob paths" do
|
30
|
-
paths = path.glob("*.rb")
|
31
|
-
|
32
|
-
expect(paths.count).to be >= 1
|
33
|
-
end
|
34
|
-
|
35
|
-
it "can be used as key in hash" do
|
36
|
-
cache = {}
|
37
|
-
|
38
|
-
cache[path.glob("*.rb")] = true
|
39
|
-
|
40
|
-
expect(cache).to be_include(path.glob("*.rb"))
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should print nice string represenation" do
|
44
|
-
glob = Build::Files::Glob.new(".", "*.rb")
|
45
|
-
|
46
|
-
expect("#{glob}").to be == '<Glob "."/"*.rb">'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -1,182 +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/list'
|
23
|
-
require 'build/files/glob'
|
24
|
-
|
25
|
-
module Build::Files::ListSpec
|
26
|
-
include Build::Files
|
27
|
-
|
28
|
-
describe Build::Files::Paths do
|
29
|
-
let(:path) {Path.new("/foo/bar/baz", "/foo")}
|
30
|
-
|
31
|
-
it "should be inspectable" do
|
32
|
-
paths = Paths.new(path)
|
33
|
-
|
34
|
-
expect(paths.inspect).to be_include path.inspect
|
35
|
-
end
|
36
|
-
|
37
|
-
it "should be possible to convert to paths" do
|
38
|
-
paths = Paths.new(path)
|
39
|
-
|
40
|
-
expect(paths.to_paths).to be paths
|
41
|
-
end
|
42
|
-
|
43
|
-
it "should be count number of paths" do
|
44
|
-
paths = Paths.new(path)
|
45
|
-
|
46
|
-
expect(paths.count).to be == 1
|
47
|
-
end
|
48
|
-
|
49
|
-
it "should coerce array to paths" do
|
50
|
-
paths = Paths.coerce([path])
|
51
|
-
|
52
|
-
expect(paths).to be_kind_of Paths
|
53
|
-
expect(paths.count).to be == 1
|
54
|
-
expect(paths).to be_include path
|
55
|
-
|
56
|
-
same_paths = Paths.coerce(paths)
|
57
|
-
expect(same_paths).to be paths
|
58
|
-
end
|
59
|
-
|
60
|
-
it "can add two lists of paths together" do
|
61
|
-
paths_a = Paths.new(path)
|
62
|
-
paths_b = Paths.new(Path.join('/foo/bar', 'alice'))
|
63
|
-
|
64
|
-
paths = paths_a + paths_b
|
65
|
-
|
66
|
-
expect(paths.count).to be 2
|
67
|
-
expect(paths).to be_include path
|
68
|
-
expect(paths).to be_kind_of Composite
|
69
|
-
|
70
|
-
# Composite equality
|
71
|
-
expect(paths).to be_eql paths
|
72
|
-
expect(paths).to_not be_eql paths_a
|
73
|
-
end
|
74
|
-
|
75
|
-
it "maps paths with a new extension" do
|
76
|
-
paths = Paths.new([
|
77
|
-
Path.join('/foo/bar', 'alice'),
|
78
|
-
Path.join('/foo/bar', 'bob'),
|
79
|
-
Path.join('/foo/bar', 'charles'),
|
80
|
-
path
|
81
|
-
])
|
82
|
-
|
83
|
-
expect(paths).to include(path)
|
84
|
-
|
85
|
-
expect(paths).to be_intersects(paths)
|
86
|
-
expect(paths).to_not be_intersects(Paths::NONE)
|
87
|
-
|
88
|
-
mapped_paths = paths.map {|path| path + ".o"}
|
89
|
-
|
90
|
-
expect(mapped_paths).to be_kind_of(Paths)
|
91
|
-
expect(mapped_paths.roots).to be == paths.roots
|
92
|
-
end
|
93
|
-
|
94
|
-
it "globs multiple files" do
|
95
|
-
glob = Glob.new(__dir__, '*.rb')
|
96
|
-
|
97
|
-
expect(glob.count).to be > 1
|
98
|
-
|
99
|
-
mapped_paths = glob.map {|path| path + ".txt"}
|
100
|
-
|
101
|
-
expect(glob.roots).to be == mapped_paths.roots
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should intersect one file in the glob" do
|
105
|
-
# Glob all test files:
|
106
|
-
glob = Glob.new(__dir__, "*.rb")
|
107
|
-
|
108
|
-
expect(glob.count).to be > 0
|
109
|
-
|
110
|
-
# Should include this file:
|
111
|
-
expect(glob).to include(__FILE__)
|
112
|
-
|
113
|
-
# Glob should intersect self:
|
114
|
-
expect(glob).to be_intersects(glob)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "should include composites" do
|
118
|
-
lib = File.join(__dir__, "../lib")
|
119
|
-
|
120
|
-
test_glob = Glob.new(__dir__, "*.rb")
|
121
|
-
lib_glob = Glob.new(lib, "*.rb")
|
122
|
-
|
123
|
-
both = test_glob + lib_glob
|
124
|
-
|
125
|
-
# List#roots is the generic accessor for Lists
|
126
|
-
expect(both.roots).to include test_glob.root
|
127
|
-
|
128
|
-
# The composite should include both:
|
129
|
-
expect(both).to include(__FILE__)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "should have path with correct root" do
|
133
|
-
test_glob = Glob.new(__dir__, "*.rb")
|
134
|
-
|
135
|
-
expect(test_glob.first).to be_kind_of Path
|
136
|
-
|
137
|
-
expect(test_glob.first.root).to be == __dir__
|
138
|
-
end
|
139
|
-
|
140
|
-
it "maps paths with new extension" do
|
141
|
-
glob = Glob.new(__dir__, "*.rb")
|
142
|
-
|
143
|
-
paths = glob.map {|path| path.append ".txt"}
|
144
|
-
|
145
|
-
expect(paths.first).to be == (glob.first.append ".txt")
|
146
|
-
expect(paths.first.to_s).to be_end_with ".rb.txt"
|
147
|
-
end
|
148
|
-
|
149
|
-
it "should map paths using with" do
|
150
|
-
glob = Glob.new(__dir__, "*.rb")
|
151
|
-
|
152
|
-
paths = glob.with extension: ".txt"
|
153
|
-
path = paths.first
|
154
|
-
|
155
|
-
expect(path).to be_kind_of Array
|
156
|
-
|
157
|
-
expect(path[0]).to be == glob.first
|
158
|
-
expect(path[1]).to be == glob.first.append(".txt")
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should define an empty set of files" do
|
162
|
-
expect(Paths::NONE).to be_kind_of List
|
163
|
-
|
164
|
-
expect(Paths::NONE.count).to be 0
|
165
|
-
end
|
166
|
-
|
167
|
-
it "can be used as key in hash" do
|
168
|
-
cache = {}
|
169
|
-
|
170
|
-
cache[Paths.new(path)] = true
|
171
|
-
|
172
|
-
expect(cache).to be_include(Paths.new(path))
|
173
|
-
end
|
174
|
-
|
175
|
-
it "can be constructed from a list of relative paths" do
|
176
|
-
paths = Paths.directory('/foo', ['bar', 'baz', 'bob'])
|
177
|
-
|
178
|
-
expect(paths.count).to be 3
|
179
|
-
expect(paths).to be_include Path.new('/foo/bar')
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,90 +0,0 @@
|
|
1
|
-
#!/usr/bin/env rspec
|
2
|
-
|
3
|
-
# Copyright, 2015, by Samuel G. D. Williams. <http://www.codeotaku.com>
|
4
|
-
#
|
5
|
-
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
# of this software and associated documentation files (the "Software"), to deal
|
7
|
-
# in the Software without restriction, including without limitation the rights
|
8
|
-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
# copies of the Software, and to permit persons to whom the Software is
|
10
|
-
# furnished to do so, subject to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included in
|
13
|
-
# all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
# THE SOFTWARE.
|
22
|
-
|
23
|
-
require 'build/files/monitor'
|
24
|
-
require 'build/files/path'
|
25
|
-
require 'build/files/system'
|
26
|
-
require 'build/files/directory'
|
27
|
-
|
28
|
-
RSpec.shared_examples_for Monitor do |driver|
|
29
|
-
let(:root) {Build::Files::Path.expand('tmp', __dir__)}
|
30
|
-
let(:path) {root + "test.txt"}
|
31
|
-
|
32
|
-
before do
|
33
|
-
root.delete
|
34
|
-
root.create
|
35
|
-
end
|
36
|
-
|
37
|
-
let(:directory) {Build::Files::Directory.new(root)}
|
38
|
-
let(:monitor) {Build::Files::Monitor.new}
|
39
|
-
|
40
|
-
it "should include touched path" do
|
41
|
-
path.touch
|
42
|
-
|
43
|
-
expect(directory.to_a).to include(path)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should detect additions' do
|
47
|
-
changed = false
|
48
|
-
|
49
|
-
monitor.track_changes(directory) do |state|
|
50
|
-
changed = true
|
51
|
-
|
52
|
-
expect(state.added).to include(path)
|
53
|
-
end
|
54
|
-
|
55
|
-
thread = Thread.new do
|
56
|
-
sleep 1
|
57
|
-
path.touch
|
58
|
-
end
|
59
|
-
|
60
|
-
monitor.run do
|
61
|
-
throw :interrupt if changed
|
62
|
-
end
|
63
|
-
|
64
|
-
thread.join
|
65
|
-
|
66
|
-
expect(changed).to be true
|
67
|
-
end
|
68
|
-
|
69
|
-
it "should add and remove monitored paths" do
|
70
|
-
handler = monitor.track_changes(directory) do |state|
|
71
|
-
# Do nothing.
|
72
|
-
end
|
73
|
-
|
74
|
-
expect(monitor.roots).to be_include root
|
75
|
-
|
76
|
-
handler.remove!
|
77
|
-
|
78
|
-
expect(monitor.roots).to be_empty
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
RSpec.describe Build::Files::Monitor::Polling do
|
83
|
-
it_behaves_like Monitor
|
84
|
-
end
|
85
|
-
|
86
|
-
if defined? Build::Files::Monitor::Native
|
87
|
-
RSpec.describe Build::Files::Monitor::Native do
|
88
|
-
it_behaves_like Monitor
|
89
|
-
end
|
90
|
-
end
|
@@ -1,205 +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 add nil root" do
|
96
|
-
expect(subject / nil).to be == subject
|
97
|
-
end
|
98
|
-
|
99
|
-
it "should be inspectable" do
|
100
|
-
expect(subject.inspect).to be_include subject.root.to_s
|
101
|
-
expect(subject.inspect).to be_include subject.relative_path.to_s
|
102
|
-
end
|
103
|
-
|
104
|
-
it "should convert to path" do
|
105
|
-
pathname = Pathname("/foo/bar/baz")
|
106
|
-
|
107
|
-
expect(Build::Files::Path[pathname]).to be == subject
|
108
|
-
expect(Build::Files::Path["/foo/bar/baz"]).to be == subject
|
109
|
-
end
|
110
|
-
|
111
|
-
it "should be equal" do
|
112
|
-
expect(subject).to be_eql subject
|
113
|
-
expect(subject).to be == subject
|
114
|
-
|
115
|
-
different_root_path = Build::Files::Path.join("/foo/bar", "baz")
|
116
|
-
expect(subject).to_not be_eql different_root_path
|
117
|
-
expect(subject).to be == different_root_path
|
118
|
-
end
|
119
|
-
|
120
|
-
it "should convert to string" do
|
121
|
-
expect(subject.to_s).to be == "/foo/bar/baz"
|
122
|
-
|
123
|
-
# The to_str method should return the full path (i.e. the same as to_s):
|
124
|
-
expect(subject.to_s).to be == subject.to_str
|
125
|
-
|
126
|
-
# Check the equality operator:
|
127
|
-
expect(subject).to be == subject.dup
|
128
|
-
|
129
|
-
# The length should be reported correctly:
|
130
|
-
expect(subject.length).to be == subject.to_s.length
|
131
|
-
|
132
|
-
# Check the return types:
|
133
|
-
expect(subject).to be_kind_of Build::Files::Path
|
134
|
-
expect(subject.root).to be_kind_of String
|
135
|
-
expect(subject.relative_path).to be_kind_of String
|
136
|
-
end
|
137
|
-
|
138
|
-
it "should consist of parts" do
|
139
|
-
expect(subject.parts).to be == ["", "foo", "bar", "baz"]
|
140
|
-
|
141
|
-
expect(subject.root).to be == "/foo"
|
142
|
-
|
143
|
-
expect(subject.relative_path).to be == "bar/baz"
|
144
|
-
|
145
|
-
expect(subject.relative_parts).to be == ["bar", "baz"]
|
146
|
-
end
|
147
|
-
|
148
|
-
it "should have a new extension" do
|
149
|
-
renamed_path = subject.with(root: '/tmp', extension: '.txt')
|
150
|
-
|
151
|
-
expect(renamed_path.root).to be == '/tmp'
|
152
|
-
|
153
|
-
expect(renamed_path.relative_path).to be == 'bar/baz.txt'
|
154
|
-
|
155
|
-
object_path = subject.append(".o")
|
156
|
-
|
157
|
-
expect(object_path.root).to be == "/foo"
|
158
|
-
expect(object_path.relative_path).to be == "bar/baz.o"
|
159
|
-
end
|
160
|
-
|
161
|
-
it "should append a path" do
|
162
|
-
subject = Build::Files::Path.new("/a/b/c")
|
163
|
-
|
164
|
-
expect(subject + "d/e/f").to be == "/a/b/c/d/e/f"
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should give a list of components" do
|
168
|
-
expect(Build::Files::Path.components(subject)).to be == ["", "foo", "bar", "baz"]
|
169
|
-
expect(Build::Files::Path.components(subject.to_s)).to be == ["", "foo", "bar", "baz"]
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should give a basename" do
|
173
|
-
expect(subject.basename).to be == "baz"
|
174
|
-
end
|
175
|
-
|
176
|
-
it "should have a new root" do
|
177
|
-
rerooted_path = subject / "cat"
|
178
|
-
|
179
|
-
expect(rerooted_path.root).to be == "/foo/bar/baz"
|
180
|
-
expect(rerooted_path.relative_path).to be == "cat"
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should give correct modes for reading" do
|
184
|
-
expect(subject.for_reading).to be == [subject.to_s, File::RDONLY]
|
185
|
-
end
|
186
|
-
|
187
|
-
it "should give correct modes for writing" do
|
188
|
-
expect(subject.for_writing).to be == [subject.to_s, File::CREAT|File::TRUNC|File::WRONLY]
|
189
|
-
end
|
190
|
-
|
191
|
-
it "should give correct modes for appending" do
|
192
|
-
expect(subject.for_appending).to be == [subject.to_s, File::CREAT|File::APPEND|File::WRONLY]
|
193
|
-
end
|
194
|
-
|
195
|
-
it "should match against relative path" do
|
196
|
-
expect(subject.match(subject.relative_path)).to be_truthy
|
197
|
-
expect(subject.match("*/baz")).to be_truthy
|
198
|
-
expect(subject.match("/baz")).to be_falsey
|
199
|
-
end
|
200
|
-
|
201
|
-
it "should match against absolute path" do
|
202
|
-
expect(subject.match(subject.to_s)).to be_truthy
|
203
|
-
expect(subject.match("/foo/**")).to be_truthy
|
204
|
-
end
|
205
|
-
end
|