You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TestContext.WriteLine throwing System.FormatException when json string is passed. #8
TestContext.WriteLine throwing System.FormatException when json string is passed.
Method Signature: public abstract void WriteLine(string format, params object[] args);
Steps to reproduce
Create a unit test project, add MSTest.TestFramework dll and execute the below test method
[TestClass]
public class UnitTest1
{
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
[TestMethod]
public void TestMethod1()
{
var msg = "{curly braces}";
//Debug.WriteLine(msg);
TestContext.WriteLine(msg);
}
}
Expected behavior
Test sholuld pass, user should be able to write the json in output.
Actual behavior
Test is failing with System.FormatException.
RCA :
This is happening because string.format is used for implementing this API and it expects format which placeholders {0}, {1}, etc. and corresponding arguments.
But when json string is passed, it just throws System.FormatException as string is present inside curly braces.
Workaround:
As a workaround, user has to add one extra curly brace for every curly brace present in string.
string str = "{{mystring}}";
Fix :
Do not use string.format api when count of arguments are null in implementation of API public abstract void WriteLine(string format, params object[] args);
Harsh Jain (@harshjain2) : This is actually an API with a format and an args. I think the right fix here is to have another API like so
public abstract void WriteLine(string message)
and the user takes care of formatting in any way he/she chooses.
Activity
AbhitejJohn commentedon Sep 29, 2016
Harsh Jain (@harshjain2) : This is actually an API with a format and an args. I think the right fix here is to have another API like so
public abstract void WriteLine(string message)
and the user takes care of formatting in any way he/she chooses.
This is similar to how Console.WriteLine works today.
Reference: http://referencesource.microsoft.com/#mscorlib/system/console.cs,2141
AbhitejJohn commentedon Oct 20, 2016
👍
Merge pull request microsoft#8 from codito/build-runtime
Address review feedback on Dim 22 / perf / IPC / dimension count
Document GitHubActionsRepositoryRoot process-lifetime cache (Amaury r…