Whither JSONDecoder tests?

I'm looking into the possibility of improving the debug output of DecodingError, especially when used with JSONDecoder, as prompted by this post.

I was wondering if there are existing tests for JSONDecoder? I found JSONEncoderTests.swift, but I didn't see an equivalent for JSONDecoder. This seems to hold true even in this draft PR to migrate swift-foundation to swift-testing.

My questions:

  1. If I want to test how well JSONDecoder produces instances of DecodingError, and then how well DecodingError prints debug output, where would I do that? I see that DecodingError is defined here, so I guess I can add the conformance and add the debug output there.
  2. What about testing that JSONDecoder produces the correct errors on failure? Are there tests somewhere that I couldn't find, or are they missing?

JSONEncoderTests.swift is a slightly deceiving name - it is a test suite for both JSONEncoder and JSONDecoder, it just happens that a lot of things that test decoding first encode the information and test decoding it, but others (like test_JSONFailTests) test just JSONDecoder. So any JSONDecoder specific tests can go into JSONEncoderTests.swift in swift-foundation.

That being said, as DecodingError is defined in the standard library I think tests for DecodingError in specific are also best put in the standard library so that'd likely be where the basic tests for DecodingError would go. The JSONDecoder tests in swift-foundation could include any JSONDecoder specific validations beyond those.

1 Like

There are some tests that test the contents of the produced error, but very few, unfortunately.

I see test_topLevelFragmentsWithGarbage, testDecodingDictionaryFailureKeyPathNested, and testDecodingStringExpectedType.