Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

u3d/install: verify package names before we ensure setup coherence (fixes #385) (regression from 1.2.0) #387

Merged
merged 4 commits into from
Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/u3d/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,15 @@ def install(args: [], options: {})

definition = UnityVersionDefinition.new(version, os, cache_versions)
unity = check_unity_presence(version: version)
packages = options[:packages] || ['Unity']

packages = verify_package_names(options[:packages], definition) || ['Unity']

begin
packages = enforce_setup_coherence(packages, options, unity, definition)
rescue InstallationSetupError
return
end

verify_package_names(definition, packages)

get_administrative_privileges(options) if options[:install]

files = Downloader.fetch_modules(definition, packages: packages, download: options[:download])
Expand Down Expand Up @@ -274,10 +273,12 @@ def cache_versions(os, offline: false, force_refresh: false, central_cache: true
cache_versions
end

def verify_package_names(definition, packages)
packages.each do |package|
UI.user_error! "package '#{package}' doesn't exist" unless definition.available_package? package
def verify_package_names(packages, definition)
unless packages.nil?
invalid_packages = packages.reject { |package| definition.available_package? package }
raise ArgumentError, "Package(s) '#{invalid_packages.join(',')}' are not known. Use #{definition.available_packages.join(',')}" unless invalid_packages.empty?
end
packages
end

def specified_or_current_project_version(version)
Expand Down
30 changes: 28 additions & 2 deletions spec/u3d/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@
it 'crashes error when specifying a non existing version' do
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })

expect(U3dCore::UI).to receive(:crash!).with(/No version 'not.a.version'/)

U3d::Commands.install(
Expand All @@ -344,6 +343,33 @@
}
)
end

# request a non existing package -> fail
it 'crashes error when specifying a non existing package' do
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })
allow(U3d::Helper).to receive(:data_path) { 'whatever' }

expected_definition(
'1.2.3f4',
:fakeos,
'fakeurl',
packages: [
U3d::UnityModule.new(id: 'unity')
]
)

expect do
U3d::Commands.install(
args: ['1.2.3f4'],
options: {
install: false,
download: true,
packages: ['not.a.package']
}
)
end.to raise_error ArgumentError, /'not.a.package'/
end
# support downloading the not current platform -> not yet supported
# TODO: Implement me
xit 'downloads versions for other os when option --operating_system is specified' do
Expand Down Expand Up @@ -667,7 +693,7 @@
# TODO: Implement me
end

describe 'platforms without modules' do
context 'platforms without modules' do
# install a non discovered version -> installed
it 'installs Unity when version is not yet present' do
on_linux
Expand Down