Skip to content

Commit 60f1fa1

Browse files
committed
Fix installed list can distinguish beta version
fix: xcpretty#384
1 parent fbed9da commit 60f1fa1

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

lib/xcode/install.rb

+14-4
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,16 @@ def open_release_notes_url(version)
300300
end
301301

302302
def list_annotated(xcodes_list)
303-
installed = installed_versions.map(&:version)
303+
installed = installed_versions.map(&:appname_version)
304+
304305
xcodes_list.map do |x|
305-
xcode_version = x.split(' ').first # exclude "beta N", "for Lion".
306-
xcode_version << '.0' unless xcode_version.include?('.')
306+
xcode_version = x.split(' ') # split version and "beta N", "for Lion"
307+
xcode_version[0] << '.0' unless xcode_version[0].include?('.')
308+
309+
# to match InstalledXcode.appname_version format
310+
version = Gem::Version.new(xcode_version.join('.'))
307311

308-
installed.include?(xcode_version) ? "#{x} (installed)" : x
312+
installed.include?(version) ? "#{x} (installed)" : x
309313
end.join("\n")
310314
end
311315

@@ -601,6 +605,12 @@ def bundle_version
601605
@bundle_version ||= Gem::Version.new(bundle_version_string)
602606
end
603607

608+
def appname_version
609+
appname = @path.basename('.app').to_s
610+
version_string = appname.split('-').last
611+
Gem::Version.new(version_string)
612+
end
613+
604614
def uuid
605615
@uuid ||= plist_entry(':DVTPlugInCompatibilityUUID')
606616
end

spec/list_spec.rb

+16-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ def fake_xcodes(*names)
2323
end
2424

2525
def fake_installed_xcode(name)
26-
xcode_path = "/Applications/Xcode-#{name}.app"
27-
xcode_version = name
26+
installed_name = name.split(' ').join('.')
27+
xcode_path = "/Applications/Xcode-#{installed_name}.app"
28+
xcode_version = name.split(' ').first
2829
xcode_version << '.0' unless name.include? '.'
2930

3031
installed_xcode = InstalledXcode.new(xcode_path)
@@ -49,9 +50,21 @@ def fake_installed_xcodes(*names)
4950
describe '#list_annotated' do
5051
it 'lists all versions with annotations' do
5152
fake_xcodes '1', '2.3', '2.3.1', '2.3.2', '3 some', '4.3.1 for Lion', '9.4.1', '10 beta'
52-
fake_installed_xcodes '2.3', '4.3.1', '10'
53+
fake_installed_xcodes '2.3', '4.3.1 for Lion', '10 beta'
5354
installer.list.should == "1\n2.3 (installed)\n2.3.1\n2.3.2\n3 some\n4.3.1 for Lion (installed)\n9.4.1\n10 beta (installed)"
5455
end
56+
57+
it 'distinguish between beta and official_version' do
58+
fake_xcodes '11.4', '11.4 beta'
59+
fake_installed_xcodes '11.4'
60+
installer.list.should == "11.4 (installed)\n11.4 beta"
61+
end
62+
63+
it 'distinguish each beta versions' do
64+
fake_xcodes '11.4 beta', '11.4 beta 3'
65+
fake_installed_xcodes '11.4 beta'
66+
installer.list.should == "11.4 beta (installed)\n11.4 beta 3"
67+
end
5568
end
5669
end
5770
end

0 commit comments

Comments
 (0)