From aab61f13d31538b2a70e53435d539121e5fd4c8a Mon Sep 17 00:00:00 2001 From: Egor Chesakov Date: Sat, 13 Apr 2019 12:09:53 -0700 Subject: [PATCH] Use xUnit TestOutputHelper to get proper test output in Azure DevOps Tests Explorer (#23957) --- tests/runtest.proj | 75 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/tests/runtest.proj b/tests/runtest.proj index 20b89a9..3f1faa8 100644 --- a/tests/runtest.proj +++ b/tests/runtest.proj @@ -166,6 +166,7 @@ $(_XunitEpilog) <_XunitProlog Condition=" '$(_XunitProlog)'=='' "> allOutput = new List()%3B + try { - sErrorText = System.IO.File.ReadAllText(errorFile)%3B + allOutput.AddRange(System.IO.File.ReadAllLines(errorFile))%3B } - catch(Exception ex) + catch (Exception ex) { - sErrorText = $"Unable to read error file: {errorFile}\n{ex}"%3B + allOutput.Add("Unable to read error file: " + errorFile)%3B + allOutput.Add(ex.Message)%3B } - string outputText = null%3B + allOutput.Add(string.Empty)%3B + allOutput.Add("Return code: " + ret)%3B + allOutput.Add("Raw output file: " + outputFile)%3B + allOutput.Add("Raw output:")%3B + try { - System.IO.StreamReader outputReader = new System.IO.StreamReader(outputFile)%3B - outputText = outputReader.ReadToEnd()%3B - outputReader.Close()%3B + allOutput.AddRange(System.IO.File.ReadAllLines(outputFile))%3B } catch(Exception ex) { - outputText = $"Unable to read error file: {outputFile}\n{ex}"%3B + allOutput.Add("Unable to read output file: " + outputFile)%3B + allOutput.Add(ex.Message)%3B } - string msg = infraEx != null ? "Test Infrastructure Failure: " + infraEx.ToString() - : sErrorText + "\n\n" + - "Return code: " + ret + "\n" + - "Raw output file: " + outputFile + "\n" + - "Raw output:\n" + outputText + "\n" + - "To run the test:\n" + - "> set CORE_ROOT=" + _Global.coreRoot + "\n" + - "> " + testExecutable + "\n"%3B + allOutput.Add("To run the test:")%3B + allOutput.Add("> set CORE_ROOT=" + _Global.coreRoot)%3B + allOutput.Add("> " + testExecutable)%3B + + foreach (string line in allOutput) + { + output.WriteLine(line)%3B + } - Assert.True(ret == CoreclrTestWrapperLib.EXIT_SUCCESS_CODE, msg)%3B + Assert.True(false, string.Join(Environment.NewLine, allOutput))%3B } } - } + } ]]> @@ -357,7 +374,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). - @@ -401,7 +418,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). hostpolicy dll - + libhostfxr so @@ -410,9 +427,9 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). $(HostFxrFileExtension) dotnet - + - @@ -434,17 +451,17 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). - @@ -468,7 +485,7 @@ namespace $([System.String]::Copy($(Category)).Replace(".","_").Replace("\",""). + Condition=" '$(GenerateTestHost)'=='true' "/> -- 2.7.4