Skip to content

Commit 1d216bc

Browse files
authored
Merge pull request #2235 from reitermarkus/spec-plist
Merge Plist spec with SystemCommand::Result spec.
2 parents e156a5d + c97f8dc commit 1d216bc

File tree

4 files changed

+62
-100
lines changed

4 files changed

+62
-100
lines changed

Library/Homebrew/cask/lib/hbc.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ module Hbc; end
3737
require "hbc/version"
3838
require "utils"
3939

40-
require "vendor/plist/plist"
41-
4240
module Hbc
4341
include Locations
4442
include Scopes

Library/Homebrew/cask/lib/hbc/system_command.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require "open3"
22
require "shellwords"
3+
require "vendor/plist/plist"
34

45
require "extend/io"
56

@@ -167,16 +168,6 @@ def self._parse_plist(command, output)
167168
EOS
168169
end
169170
xml
170-
rescue Plist::ParseError => e
171-
raise CaskError, <<-EOS
172-
Error parsing plist output from command.
173-
command was:
174-
#{command.utf8_inspect}
175-
error was:
176-
#{e}
177-
output we attempted to parse:
178-
#{output}
179-
EOS
180171
end
181172
end
182173
end
Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1+
require "hbc/system_command"
2+
13
describe Hbc::SystemCommand::Result do
24
describe "::_parse_plist" do
5+
subject { described_class._parse_plist(command, input) }
36
let(:command) { Hbc::SystemCommand.new("/usr/bin/true", {}) }
4-
let(:hdiutil_output) {
7+
let(:plist) {
58
<<-EOS.undent
6-
Hello there! I am in no way XML am I?!?!
7-
8-
That's a little silly... you were expexting XML here!
9-
10-
What is a parser to do?
11-
12-
Hopefully <not> explode!
13-
149
<?xml version="1.0" encoding="UTF-8"?>
1510
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
1611
<plist version="1.0">
1712
<dict>
1813
<key>system-entities</key>
1914
<array>
15+
<dict>
16+
<key>content-hint</key>
17+
<string>Apple_partition_map</string>
18+
<key>dev-entry</key>
19+
<string>/dev/disk3s1</string>
20+
<key>potentially-mountable</key>
21+
<false/>
22+
<key>unmapped-content-hint</key>
23+
<string>Apple_partition_map</string>
24+
</dict>
25+
<dict>
26+
<key>content-hint</key>
27+
<string>Apple_partition_scheme</string>
28+
<key>dev-entry</key>
29+
<string>/dev/disk3</string>
30+
<key>potentially-mountable</key>
31+
<false/>
32+
<key>unmapped-content-hint</key>
33+
<string>Apple_partition_scheme</string>
34+
</dict>
2035
<dict>
2136
<key>content-hint</key>
2237
<string>Apple_HFS</string>
@@ -37,11 +52,44 @@
3752
EOS
3853
}
3954

40-
it "ignores garbage output before xml starts" do
41-
parsed = described_class._parse_plist(command, hdiutil_output)
55+
context "when output contains garbage" do
56+
let(:input) {
57+
<<-EOS.undent
58+
Hello there! I am in no way XML am I?!?!
59+
60+
That's a little silly... you were expexting XML here!
61+
62+
What is a parser to do?
63+
64+
Hopefully <not> explode!
65+
66+
#{plist}
67+
EOS
68+
}
69+
70+
it "ignores garbage before xml" do
71+
expect(subject.keys).to eq(["system-entities"])
72+
expect(subject["system-entities"].length).to eq(3)
73+
end
74+
end
75+
76+
context "given a hdiutil output as input" do
77+
let(:input) { plist }
78+
79+
it "successfully parses it" do
80+
expect(subject.keys).to eq(["system-entities"])
81+
expect(subject["system-entities"].length).to eq(3)
82+
expect(subject["system-entities"].map { |e| e["dev-entry"] })
83+
.to eq(["/dev/disk3s1", "/dev/disk3", "/dev/disk3s2"])
84+
end
85+
end
86+
87+
context "given an empty input" do
88+
let(:input) { "" }
4289

43-
expect(parsed.keys).to eq(["system-entities"])
44-
expect(parsed["system-entities"].length).to eq(1)
90+
it "raises an error" do
91+
expect { subject }.to raise_error(Hbc::CaskError, /Empty plist input/)
92+
end
4593
end
4694
end
4795
end

Library/Homebrew/cask/spec/plist/parser_spec.rb

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)