dn-m / MusicXML

Implementation of the musicXML specification in Swift
MIT License
75 stars 20 forks source link

Tests failing on clean checkout #235

Open pcantrell opened 3 years ago

pcantrell commented 3 years ago

When I do a clean checkout of the project and run tests, either with swift test from the command line or in Xcode, I get 6 similar-looking failures:

Test Case '-[MusicXMLTests.HelloWorld testHelloWorldDecoding]' started.
/Users/paul/work/opensource/MusicXML/.build/checkouts/XMLCoder/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift:459: error: -[MusicXMLTests.HelloWorld testHelloWorldDecoding] : failed: caught error: "typeMismatch(MusicXML.PartList.Item, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "part-list", intValue: nil), XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))"
Test Case '-[MusicXMLTests.HelloWorld testHelloWorldDecoding]' failed (0.006 seconds).

❌ Partwise/01a-Pitches-Pitches.xml
/Users/paul/work/opensource/MusicXML/Tests/MusicXMLTests/LilyPondTests/LilyPondTestSuite.swift:39: error: -[MusicXMLTests.LilyPondTests testAll] : failed: caught error: "typeMismatch(MusicXML.PartList.Item, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "part-list", intValue: nil), XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))"
Test Case '-[MusicXMLTests.LilyPondTests testAll]' failed (0.022 seconds).

/Users/paul/work/opensource/MusicXML/.build/checkouts/XMLCoder/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift:459: error: -[MusicXMLTests.PartNameTests testDecodingPartName] : failed: caught error: "typeMismatch(MusicXML.NameDisplay.Text, Swift.DecodingError.Context(codingPath: [XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))"
Test Case '-[MusicXMLTests.PartNameTests testDecodingPartName]' failed (0.001 seconds).

/Users/paul/work/opensource/MusicXML/.build/checkouts/XMLCoder/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift:459: error: -[MusicXMLTests.ReveTests testIdentification] : failed: caught error: "typeMismatch(MusicXML.Encoding.Kind, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "encoding", intValue: nil), XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))"
Test Case '-[MusicXMLTests.ReveTests testIdentification]' failed (0.001 seconds).

🎼 Test score: SchbAvMaSample
  Path: /Users/paul/work/opensource/MusicXML/Tests/MusicXMLTests/ScoreTests/MusicXMLSamples/SchbAvMaSample/SchbAvMaSample.musicxml
  Source: https://www.musicxml.com/music-in-musicxml/example-set/
  ❌ Parsing failed: typeMismatch(MusicXML.Encoding.Kind, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "identification", intValue: nil), CodingKeys(stringValue: "encoding", intValue: nil), XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))
/Users/paul/work/opensource/MusicXML/Tests/MusicXMLTests/ScoreTests/ScoreTestSuite.swift:79: error: -[MusicXMLTests.ScoreTests testAll] : failed: caught error: "typeMismatch(MusicXML.Encoding.Kind, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "identification", intValue: nil), CodingKeys(stringValue: "encoding", intValue: nil), XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))"
Test Case '-[MusicXMLTests.ScoreTests testAll]' failed (0.133 seconds).

/Users/paul/work/opensource/MusicXML/.build/checkouts/XMLCoder/Sources/XMLCoder/Decoder/XMLDecoderImplementation.swift:459: error: -[MusicXMLTests.TupletsTremoloTest testTupletsTremolo] : failed: caught error: "typeMismatch(MusicXML.PartList.Item, Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "part-list", intValue: nil), XMLKey(stringValue: "0", intValue: 0), XMLKey(stringValue: "0", intValue: 0)], debugDescription: "Unrecognized choice", underlyingError: nil))"
Test Case '-[MusicXMLTests.TupletsTremoloTest testTupletsTremolo]' failed (0.008 seconds).

Is this expected — the current HEAD just in an intermediate state? Or is it a regression with a newer version of Swift, perhaps? I’m using 5.3.1.

pcantrell commented 3 years ago

The problem appears to stem from the parsing trying to apply XMLChoiceDecodingContainer to XML text elements that contain nothing but whitespace. Stripping all whitespace from between tags in the XML makes at least the HelloWorld test pass.

pcantrell commented 3 years ago

…and the problem seems to have appeared in this commit whose message is “flag failing test,” so I take it you’re already aware of the problem?

Note that if I set trimValueWhitespaces to false throughout the project, it fixes the issues — but then tests that seem to be explicitly testing for whitespace preservation fail.

pcantrell commented 3 years ago

More debugging: It works pointing at XMLCoder’s commit that merged @bwetherfield’s https://github.com/MaxDesiatov/XMLCoder/pull/155, but fails with the next commit in XMLCoder’s history, which merges https://github.com/MaxDesiatov/XMLCoder/pull/157. It looks like MusicXML had relied on XMLCoder stuffing all the intervening whitespace into the element’s value, as that latter PR describes, and doesn’t know how to skip the newly added intervening text nodes that contain nothing but whitespace.

The internals of the XML parsing are pretty foggy to me, but it looks like one of the following things needs to happen:

  1. MusicXML accounts for and skips blank text nodes.
  2. XMLCoder adds an option distinct from trimValueWhitespaces that drops text nodes that contain only whitespace, but preserves whitespace in text nodes that contain non-whitespace.
  3. MusicXML stops insisting that it preserve leading and trailing whitespace.