Skip to content

Update docs for decoding stdout and stderr from exit tests #1230

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

Conversation

simonjbeaumont
Copy link
Contributor

Motivation:

The API documentation for ExitTest.Result.standardOutputContent and ExitTest.Result.standardErrorContent has advice on how to construct a string from their contents. It recommends using String.init(validatingCString:), which has two problems:

  1. You cannot just pass it in since these properties are [UInt8] and String.init(validatingCString:) takes sequences whose element is CChar (aka Int8):
_ = String(validatingCString: result.standardErrorContent)  // error: Cannot convert value of type '[UInt8]' to expected argument type '[CChar]' (aka 'Array<Int8>')
  1. Even if you had the sequence of the correct element type, the matching initializer is now deprecated:
_ = String(validatingCString: result.standardErrorContent.map(Int8.init))  // warning: 'init(validatingCString:)' is deprecated: Use String(validating: array, as: UTF8.self) instead, after truncating the null termination.

So, in order to get this working without warnings, adopters will likely want this:

try #require(String(validating: result.standardErrorContent, as: UTF8.self))

Modifications:

  • Update the API documentation to advise using String(validating: array, as: UTF8.self).

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

@stmontgomery stmontgomery added bug 🪲 Something isn't working documentation 📚 Improvements or additions to documentation exit-tests ☠️ Work related to exit tests labels Jul 17, 2025
@stmontgomery stmontgomery added this to the Swift 6.x (main) milestone Jul 17, 2025
Copy link
Contributor

@stmontgomery stmontgomery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Makes sense to me, but I'll let @grynspan weigh in first

Copy link
Contributor

@grynspan grynspan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. I think I originally wrote this documentation before that initializer was added.

@stmontgomery stmontgomery merged commit 004acdb into swiftlang:main Jul 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working documentation 📚 Improvements or additions to documentation exit-tests ☠️ Work related to exit tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy