forked from rock-core/autoproj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_find_workspace.rb
62 lines (59 loc) · 2.91 KB
/
test_find_workspace.rb
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
require "autoproj/test"
require "tmpdir"
describe Autoproj do
describe ".find_v2_root_dir" do
attr_reader :workspace_root, :testdir
before do
@testdir = make_tmpdir
@workspace_root = File.join(testdir, "path", "to", "workspace")
FileUtils.mkdir_p File.join(workspace_root, ".autoproj")
FileUtils.touch File.join(workspace_root, ".autoproj", "config.yml")
FileUtils.mkdir_p File.join(workspace_root, "with", "subdir")
end
it "returns a parent path that contain an .autoproj directory" do
assert_equal workspace_root, Autoproj.find_v2_root_dir(File.join(workspace_root, "with", "subdir"), "")
assert_equal workspace_root, Autoproj.find_v2_root_dir(workspace_root, "")
end
it "expands relative paths properly" do
Dir.chdir(File.join(workspace_root, "with")) do
assert_equal workspace_root, Autoproj.find_v2_root_dir("./subdir", "")
assert_equal workspace_root, Autoproj.find_v2_root_dir("subdir", "")
end
end
it "resolves a config file value if a config file is found" do
actual_workspace = File.join(testdir, "actual_workspace")
FileUtils.mkdir_p File.join(actual_workspace, ".autoproj")
FileUtils.touch File.join(actual_workspace, ".autoproj", "config.yml")
File.open(File.join(workspace_root, ".autoproj", "config.yml"), "w") do |io|
io.puts "c: #{actual_workspace}"
end
assert_equal actual_workspace, Autoproj.find_v2_root_dir(workspace_root, "c")
end
it "raises if the config value does not point to a valid v2 workspace" do
File.open(File.join(workspace_root, ".autoproj", "config.yml"), "w") do |io|
io.puts "c: #{testdir}"
end
assert_raises(ArgumentError) do
Autoproj.find_v2_root_dir(workspace_root, "c")
end
end
it "handles a config file that points to itself" do
File.open(File.join(workspace_root, ".autoproj", "config.yml"), "w") do |io|
io.puts "c: #{workspace_root}"
end
assert_equal workspace_root, Autoproj.find_v2_root_dir(workspace_root, "c")
end
it "returns the found path if a config file is found but it does not contain the required field" do
File.open(File.join(workspace_root, ".autoproj", "config.yml"), "w") do |io|
io.puts "c: #{workspace_root}"
end
assert_equal workspace_root, Autoproj.find_v2_root_dir(workspace_root, "another_field")
end
it "returns falsey if it reaches the root path" do
assert !Autoproj.find_v2_root_dir(testdir, "")
end
it "returns nil if the path does not exist" do
assert !Autoproj.find_v2_root_dir("/does/not/exist", "")
end
end
end