Skip to content

Commit

Permalink
u3d/run: add -projectpath also when passing arguments (fixes #73) (#80)
Browse files Browse the repository at this point in the history
* u3d/run: add -projectpath also when passing arguments (fixes #73)

* cleanup
  • Loading branch information
lacostej committed Aug 24, 2017
1 parent 877f6d5 commit 5022a15
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 20 deletions.
11 changes: 7 additions & 4 deletions lib/u3d/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ def run(options: {}, run_args: [])
version = options[:unity_version]

runner = Runner.new
pp = runner.find_projectpath_in_args(run_args)
args_pp = Runner.find_projectpath_in_args(run_args)
pp = args_pp
pp = Dir.pwd unless pp
up = UnityProject.new(pp)

Expand All @@ -163,10 +164,12 @@ def run(options: {}, run_args: [])
end
end

run_args = ['-projectpath', up.path] if run_args.empty? && up.exist?
if up.exist? && args_pp.nil?
extra_run_args = ['-projectpath', up.path]
run_args = [extra_run_args, run_args].flatten
end

# we could
# * support matching 5.3.6p3 if passed 5.3.6
# we could support matching 5.3.6p3 if passed 5.3.6
unity = Installer.create.installed.find { |u| u.version == version }
UI.user_error! "Unity version '#{version}' not found" unless unity
runner.run(unity, run_args, raw_logs: options[:raw_logs])
Expand Down
28 changes: 15 additions & 13 deletions lib/u3d/unity_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,22 +77,24 @@ def find_and_prepare_logfile(installation, args)
log_file
end

# rubocop:disable MethodName
def find_logFile_in_args(args)
# rubocop:enable MethodName
find_arg_in_args('-logFile', args)
end
class << self
# rubocop:disable MethodName
def find_logFile_in_args(args)
# rubocop:enable MethodName
find_arg_in_args('-logFile', args)
end

def find_projectpath_in_args(args)
find_arg_in_args('-projectpath', args)
end
def find_projectpath_in_args(args)
find_arg_in_args('-projectpath', args)
end

def find_arg_in_args(arg_to_find, args)
raise 'Only arguments of type array supported right now' unless args.is_a?(Array)
args.each_with_index do |arg, index|
return args[index + 1] if arg == arg_to_find && index < args.count - 1
def find_arg_in_args(arg_to_find, args)
raise 'Only arguments of type array supported right now' unless args.is_a?(Array)
args.each_with_index do |arg, index|
return args[index + 1] if arg == arg_to_find && index < args.count - 1
end
nil
end
nil
end

private
Expand Down
3 changes: 2 additions & 1 deletion spec/support/setups.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ def expect_no_install
expect(U3d::Installer).to_not receive(:install_modules)
end

def in_a_project(version)
def in_a_project(version: nil, path: nil)
project = double("UnityProject")
allow(U3d::UnityProject).to receive(:new) { project }
allow(project).to receive(:path) { path }
allow(project).to receive(:exist?) { true }
allow(project).to receive(:editor_version) { version }
end
Expand Down
143 changes: 141 additions & 2 deletions spec/u3d/commands_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
# no version specified -> look for version in current project folder if any
describe 'when no version is specified' do
it 'fetches the version of the project in the current folder' do
in_a_project '1.2.3f4'
in_a_project(version: '1.2.3f4')
on_fake_os
with_fake_cache('fakeos' => { 'versions' => { '1.2.3f4' => 'fakeurl' } })

Expand Down Expand Up @@ -492,7 +492,7 @@
# no version specified -> look for version in current project folder if any
describe 'when no version is specified' do
it 'fetches the version of the project in the current folder' do
in_a_project '1.2.3f4'
in_a_project(version: '1.2.3f4')
on_fake_os
expect_privileges_check

Expand Down Expand Up @@ -768,5 +768,144 @@
# passes all lines through the log analyser with the configured (default) log rule
# QUESTION: EOL issue ? - what about logs from other platforms?
end

# ---
# RUN
# ---
describe "#run", focus: true do
let(:runner) do
runner = double("Runner")
allow(U3d::Runner).to receive(:new) { runner }
runner
end
context 'inside a given unity project' do
it "fails if it cannot find the project's unity version" do
are_installed([])
projectpath = 'fakepath'
in_a_project(version: '1.2.3f4', path: projectpath)

expect do
U3d::Commands.run(
options: {},
run_args: []
)
end.to raise_error U3dCore::Interface::UIError, "Unity version '1.2.3f4' not found"
end

it "uses the project's unity version and path if there are no arguments" do
unity = fake_installation('1.2.3f4')
projectpath = 'fakepath'

are_installed([unity])
in_a_project(version: unity.version, path: projectpath)

expect(runner).to receive(:run).with(unity, ['-projectpath', projectpath], raw_logs: nil)

U3d::Commands.run(
options: {},
run_args: []
)
end

it "uses the project's unity version and path if there are arguments" do
unity = fake_installation('1.2.3f4')
projectpath = 'fakepath'

are_installed([unity])
in_a_project(version: unity.version, path: projectpath)

expect(runner).to receive(:run).with(unity, ['-projectpath', projectpath, "somearg"], raw_logs: nil)

U3d::Commands.run(
options: {},
run_args: ["somearg"]
)
end

it "prefers the user's unity version if passed as argument" do
project_unity = fake_installation('1.2.3f4')
other_unity = fake_installation('1.2.3p1')
projectpath1 = 'fakepath'

are_installed([project_unity, other_unity])
in_a_project(version: project_unity.version, path: projectpath1)

expect(runner).to receive(:run).with(other_unity, ['-projectpath', projectpath1, "somearg"], raw_logs: nil)

U3d::Commands.run(
options: { unity_version: other_unity.version },
run_args: ["somearg"]
)
end

it "prefers the user's unity project path if passed as argument" do
project_unity = fake_installation('1.2.3f4')
current_projectpath = 'fakepath'
other_projectpath = 'fakepath2'

are_installed([project_unity])
in_a_project(version: project_unity.version, path: current_projectpath)

expect(runner).to receive(:run).with(project_unity, ['-projectpath', other_projectpath, "somearg"], raw_logs: nil)

U3d::Commands.run(
options: {},
run_args: ['-projectpath', other_projectpath, 'somearg']
)
end
end
context 'outside a unity project' do
it 'fails if no unity version specified' do
unity = fake_installation('1.2.3f4')
are_installed([unity])

runner = double("Runner")
allow(U3d::Runner).to receive(:new) { runner }

expect do
U3d::Commands.run(
options: {},
run_args: []
)
end.to raise_error U3dCore::Interface::UIError, /Not sure which version of Unity to run/
end
it "fails if the specified version isn't installed" do
nothing_installed

expect do
U3d::Commands.run(
options: { unity_version: '1.2.3f4' },
run_args: []
)
end.to raise_error U3dCore::Interface::UIError, /'1.2.3f4' not found/
end
it "runs with the specified unity, project version" do
unity = fake_installation('1.2.3f4')
projectpath = 'fakepath'

are_installed([unity])

expect(runner).to receive(:run).with(unity, ['-projectpath', projectpath], raw_logs: nil)

U3d::Commands.run(
options: { unity_version: unity.version },
run_args: ["-projectpath", projectpath]
)
end
it "runs with the specified unity, project version and raw_logs" do
unity = fake_installation('1.2.3f4')
projectpath = 'fakepath'

are_installed([unity])

expect(runner).to receive(:run).with(unity, ['-projectpath', projectpath], raw_logs: 'raaaww')

U3d::Commands.run(
options: { unity_version: unity.version, raw_logs: 'raaaww' },
run_args: ["-projectpath", projectpath]
)
end
end
end
end
end

0 comments on commit 5022a15

Please sign in to comment.