-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add custom missing mandatory UFO path error types & missing mandatory UFO path checks #146
Merged
chrissimpkins
merged 11 commits into
linebender:master
from
chrissimpkins:custom-error-expected-paths
Jul 28, 2021
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e37bc28
[error] add custom Error::MissingFile and Error::MissingUFODir error …
chrissimpkins 8670748
[font] perform UFO dir path existence validity check, raise Error::Mi…
chrissimpkins f15320d
refactor Error::MissingLayerContents error to Error::MissingFile error
chrissimpkins 7b6cb1e
Error::MissingUFODir --> Error::MissingUfoDir
chrissimpkins 6c9e817
add test UFO source files with missing metainfo.plist
chrissimpkins d9d26c4
[font] add missing metainfo.plist file check
chrissimpkins 3f12d08
add missing mandatory layercontents.plist file test + test sources
chrissimpkins a418ef2
add glyphs and background glyphs dir mandatory contents.plist file ch…
chrissimpkins 0974b9a
remove debugging println statements
chrissimpkins a25963b
pare down UFO test files
chrissimpkins b1c17ab
[font] update unit test approach to use matches! macro tests on Error…
chrissimpkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
testdata/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo/fontinfo.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>ascender</key> | ||
<integer>750</integer> | ||
<key>capHeight</key> | ||
<integer>750</integer> | ||
<key>descender</key> | ||
<integer>-250</integer> | ||
<key>familyName</key> | ||
<string>Tester MissingGlyphsContents</string> | ||
<key>guidelines</key> | ||
<array/> | ||
<key>postscriptBlueValues</key> | ||
<array/> | ||
<key>postscriptFamilyBlues</key> | ||
<array/> | ||
<key>postscriptFamilyOtherBlues</key> | ||
<array/> | ||
<key>postscriptOtherBlues</key> | ||
<array/> | ||
<key>postscriptStemSnapH</key> | ||
<array/> | ||
<key>postscriptStemSnapV</key> | ||
<array/> | ||
<key>styleName</key> | ||
<string>Regular</string> | ||
<key>unitsPerEm</key> | ||
<integer>1000</integer> | ||
<key>versionMajor</key> | ||
<integer>1</integer> | ||
<key>versionMinor</key> | ||
<integer>0</integer> | ||
<key>xHeight</key> | ||
<integer>500</integer> | ||
</dict> | ||
</plist> |
8 changes: 8 additions & 0 deletions
8
...ta/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo/glyphs.background/layerinfo.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>color</key> | ||
<string>0,0.8,0.2,0.7</string> | ||
</dict> | ||
</plist> |
8 changes: 8 additions & 0 deletions
8
testdata/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo/glyphs/contents.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>space</key> | ||
<string>space.glif</string> | ||
</dict> | ||
</plist> |
8 changes: 8 additions & 0 deletions
8
testdata/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo/glyphs/layerinfo.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>color</key> | ||
<string>1,0.75,0,0.7</string> | ||
</dict> | ||
</plist> |
7 changes: 7 additions & 0 deletions
7
testdata/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo/glyphs/space.glif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<glyph name="space" format="2"> | ||
<advance width="500"/> | ||
<unicode hex="0020"/> | ||
<outline> | ||
</outline> | ||
</glyph> |
14 changes: 14 additions & 0 deletions
14
testdata/ufo/Tester-MissingGlyphsContents-BackgroundLayer.ufo/layercontents.plist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version='1.0' encoding='UTF-8'?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<array> | ||
<array> | ||
<string>foreground</string> | ||
<string>glyphs</string> | ||
</array> | ||
<array> | ||
<string>background</string> | ||
<string>glyphs.background</string> | ||
</array> | ||
</array> | ||
</plist> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_eq!(font_load_res, Err(Error::MissingUfoDir(...)))
or something maybe?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried. Compiler won't let me perform equality comparisons on the Result Error type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things:
As written, I would do this as,
but there's probably a better option: explicitly testing for a panic with the
should_panic
attribute.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice, I didn't realize that you can add an expected string with
should_panic
. I tried this approach but I can't elicit a panic from the new custom Error. The attribute doesn't seem to catch errors like it does panics. I see this in the docs that you linked:Let me tinker with the test Result approach a bit. If I can't find a better solution, I'll transition things over the matches! macro approach above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it would work if you just
unwrap
theResult
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(but
matches!
is totally reasonable too)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the use of a Result return type in unit tests is good if you expect an Ok() but there isn't a way to expect an Err. We could return a test error when the function being tested returns Ok 💥 but that seems worse than the match pattern matching approach :)
I went with the matches! macro. That allows us to confirm the custom error type and works well!
b1c17ab