-
Notifications
You must be signed in to change notification settings - Fork 645
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
Fix culture and line endings issues in tests #7778
Conversation
Thanks for the contribution @volanavlad ! Can you please open an issue with the problem that you are fixing. We will work with you on merging this fix. |
Here is the issue: #7779 |
Regarding the newline changes, could this perhaps be due to Git configuration? I think there is a setting that tells give to checkout text files with I am surprised to see |
You are right - issues are due to git settings and default OS UI culture. |
Regarding the line ending setting - totally agree this is a bad experience. Let's fix it! If we switch to XML entities in the RESX file will that get clobbered by the Visual Studio RESX editor when we make a change to the string? |
I have just tested it. |
Could you make the change on the test side? |
Yes. I can move assert string to resx. So git setting will apply both to checked and actual strings. Test will work fine in both cases. |
…estMethodFacts.IngestsAdvisory use DateTimeOffset according to WithdrawnAt property definition
…softTeamSubscriptionFacts.TestSecurityPolicyService issue NuGet#7779
Fixed in commit '9ee4a940851e505d27ecb52d956b9ea4741f3159' |
+new issue fixed: #7783 |
Sorry NuGetGallery.Security.MicrosoftTeamSubscriptionFacts.Policies_ReturnsMicrosoftTeamSubscriptionPolicies Message: |
It is json string in policy.Value OK Wait for next commit please. |
…omplianceForPush And emulate in test the same behavior as ResX file newline converted to json string
fixed |
@@ -215,7 +215,7 @@ public void ThrowsWhenInvalidMinClientVersion(bool strict) | |||
|
|||
// Act & Assert | |||
var ex = Assert.Throws<ArgumentException>(() => PackageMetadata.FromNuspecReader(nuspec, strict)); | |||
Assert.Equal("'bad' is not a valid version string.\r\nParameter name: value", ex.Message); | |||
Assert.Equal($"'bad' is not a valid version string.\r\n{TestStrings.Parameter_name}: value", ex.Message); |
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.
Instead of supporting localization here, would it be simpler to check the param name separately? In other words:
- Assert that the message begins with
'bad' is not a valid version string.
- Assert that the
ex.ParamName
is"value"
I'm concerned that supporting all locales will be tough 😅
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.
As an alternative, see my comment below: #7778 (comment)
Why is it better to have localized strings in tests? Wouldn't it be easier to set the current culture to invariant instead of localizing the tests? It seems like we could add something like this to our unit tests: CultureInfo.CurrentCulture = CultureInfo.InvariantCulture; |
I started with this idea. But it requires much more refactoring of test code. For example - it is quite strange to change current ui culture in the middle of the test (i.e. inside assert function like tests/NuGetGallery.Facts/TestUtils/ContractAssert.cs ThrowsArgException() ) |
Ah that's a good point. What do you think of creating a new attribute for unit tests that require localization? Something like: public class InvariantCultureFactAttribute : FactAttribute
{
public InvariantCultureFactAttribute()
{
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
}
} Then the affected tests can look like: [InvariantCultureFact]
public void MyTest()
{
// The current culture is invariant now
} This way we don't need to refactor too much code 😊
Oof, that's tricky... For these tests that require multiple threads, I think it'd be best if we remove the assertions that require localization. |
Hi, @volanavlad. We are working on this problem, and seeking the best solution. Feel free to follow up this PR or the issue. Thanks! |
I don't think introducing localization is the way to go: yes, it will fix it for Russian in the short term, but I imagine other languages would have the same issues as well, and we don't want to end up supporting a dozen of localisations just for the sake of tests. I installed the Russian language pack in Windows and managed to reproduce the test failures due to exception text localization. All but two failures are due to, in my opinion, a bit too strict Out of the remaining two, Lastly, |
Hi, @volanavlad! We have a recent fix for this issue: #8021. |
Fix some tests failures:
Due to bad line endings in xml resources. Replaced to xml entities
If current culture is not invariant some tests fail due to exception messages are localized while assert strings are not. So it would be better to have localized strings in tests.