diff --git a/lib/u3d/installer.rb b/lib/u3d/installer.rb index 2b9ef47e..9c9f03d5 100644 --- a/lib/u3d/installer.rb +++ b/lib/u3d/installer.rb @@ -146,9 +146,12 @@ def package_destination(info, unity_root_path) end end + # extra installation paths are stored in U3D_EXTRA_PATHS environment variable, + # following a standard PATH variable format. + # Returns an array of ruby style paths def extra_installation_paths return [] if ENV['U3D_EXTRA_PATHS'].nil? - ENV['U3D_EXTRA_PATHS'].strip.split(File::PATH_SEPARATOR) + ENV['U3D_EXTRA_PATHS'].strip.split(File::PATH_SEPARATOR).map { |p| File.expand_path p } end def find_installations_with_path(default_root_path: '', postfix: []) diff --git a/spec/u3d/installer_spec.rb b/spec/u3d/installer_spec.rb index f8e74cfe..03ed6971 100644 --- a/spec/u3d/installer_spec.rb +++ b/spec/u3d/installer_spec.rb @@ -88,6 +88,30 @@ class DummyInstaller < U3d::BaseInstaller expect(installer.installed_sorted_by_versions).to eq(sorted_installed) end end + + describe ".extra_installation_paths" do + describe "converts paths to ruby paths" do + def expect_extra_installation_paths(env_var, expected_paths) + installer = DummyInstaller.new + with_env_values('U3D_EXTRA_PATHS' => env_var) do + expect(installer.send(:extra_installation_paths)).to eql(expected_paths) + end + end + it "works on Windows", if: WINDOWS do + expect_extra_installation_paths( + "C:\\Program Files\\Unity;D:\\", + ["C:/Program Files/Unity", "D:/"] + ) + end + + it "works on Unix", unless: WINDOWS do + expect_extra_installation_paths( + "/Applications/here:/Applications/else", + ["/Applications/here", "/Applications/else"] + ) + end + end + end end describe U3d::MacInstaller, unless: WINDOWS do diff --git a/spec/u3d_core/helper_spec.rb b/spec/u3d_core/helper_spec.rb new file mode 100644 index 00000000..1ec1634a --- /dev/null +++ b/spec/u3d_core/helper_spec.rb @@ -0,0 +1,33 @@ +## --- BEGIN LICENSE BLOCK --- +# Copyright (c) 2019-present WeWantToKnow AS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +## --- END LICENSE BLOCK --- + +require 'u3d/utils' + +describe U3dCore do + describe U3d::Helper do + describe '.windows_path' do + it 'converts paths' do + expect(U3dCore::Helper.windows_path('/path/to/file')).to eql "\\path\\to\\file" + end + end + end +end