Infer a display name for tests and suites which have a raw identifier name consisting of a single token
This tweaks the logic for inferring a display name for a test or suite which has a raw identifier name so that it will take effect even if the content of the raw identifier is a single, valid token.
Motivation:
Typically, raw identifiers (introduced in SE-0451) are intended for use when you want to include characters in the name of a test or suite which aren't valid in identifiers — such as whitespace or (some) punctuation. However, it can sometimes be useful to specify a raw identifier for a test or suite even when it isn't strictly needed, because of how the testing library implicitly uses the content of a raw identifier as the display name.
For example, consider a parameterized test function which currently has an explicit display name consisting of a single word, and has a lengthy parameter label:
@Test("Authentication", arguments: [...])
func authentication(authenticationSessionCoordinator: MyAuthenticationSession) { ... }
This test will have the plain display name Authentication and that's what will be displayed in console output and in the UI of integrated tools/IDEs. Even though the display name is only a single word, it allows the test author to precisely control how the test is presented in results and omit the lengthy parameter label, which allows the output to be cleaner and easier to understand.
Now imagine the user wishes to modernize their tests by adopting the new raw identifiers feature. They do so by switching to the following:
@Test(arguments: [...])
func `Authentication`(authenticationSessionCoordinator: MyAuthenticationSession) { ... }
In this scenario, because of an edge case in the current handling logic of the testing library, no display name will be inferred at all, and the console output and UI tools will show the full underlying name which is Authentication(authenticationSessionCoordinator:). However this isn't ideal, since the user no longer has an idiomatic way to specify the succinct display name they want using a raw identifier because it happens to consist of a single token without any whitespace or special characters. Although this can be worked around by specifying two or more words inside the raw identifier, there isn't an obvious reason why doing so is necessary and users should be permitted to specify a single valid token as a display name if they want to.
Modifications:
With the fix in this PR, the above test would have the expected display name of Authentication inferred. Specifically, this impacts the displayName, not the name, property of Test.
Checklist:
- [x] Code and documentation should follow the style of the Style Guide.
- [x] If public symbols are renamed or modified, DocC references should be updated.
@swift-ci please test
This is not a bug but intentional behaviour, as we discussed previously. It's a change in behaviour for existing test functions/suites and so it needs to be reviewed by the community via the Swift Evolution process.
@swift-ci please test