From dfb3ebd706912a3168938bfdebe7499ef56ed14f Mon Sep 17 00:00:00 2001 From: Zoltan Varga Date: Wed, 13 Mar 2019 00:31:28 -0400 Subject: [PATCH] [netcore] Improvements to gen-xunit-runner. * Add support for response files. * Fix encoding of small primitive types. * Print number of run/failed/skipped tests. --- netcore/gen-xunit-runner/Program.cs | 54 ++++++++++++++++++++++++++++++++----- netcore/gen-xunit-runner/README.md | 5 ++++ 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/netcore/gen-xunit-runner/Program.cs b/netcore/gen-xunit-runner/Program.cs index 4215f17aa34..a186b17afe5 100644 --- a/netcore/gen-xunit-runner/Program.cs +++ b/netcore/gen-xunit-runner/Program.cs @@ -68,12 +68,15 @@ class Program class CaseData { public object[] Values; + public MemberDataAttribute MemberData; + public MemberInfo Member; } static CodeExpression EncodeValue (object val) { if (val is int || val is long || val is uint || val is ulong || val is byte || val is sbyte || val is short || val is ushort || val is bool || val is string || val is char || val is float || val is double) - return new CodePrimitiveExpression (val); + //return new CodePrimitiveExpression (val); + return new CodeCastExpression (new CodeTypeReference (val.GetType ()), new CodePrimitiveExpression (val)); else if (val is Type) return new CodeTypeOfExpression ((Type)val); else if (val is Enum) { @@ -107,6 +110,20 @@ class Program var outfile_name = args [0]; var sdkdir = args [1] + "/artifacts/bin/runtime/netcoreapp-OSX-Debug-x64"; args = args.Skip (2).ToArray (); + // Response file support + var extra_args = new List (); + for (int i = 0; i < args.Length; ++i) { + var arg = args [i]; + if (arg [0] == '@') { + foreach (var line in File.ReadAllLines (arg.Substring (1))) { + if (line.Length == 0 || line [0] == '#') + continue; + extra_args.AddRange (line.Split (' ')); + } + args [i] = ""; + } + } + args = args.Where (s => s != String.Empty).Concat (extra_args).ToArray (); // Despite a lot of effort, couldn't get dotnet to load these assemblies from the sdk dir, so copy them to our binary dir File.Copy ($"{sdkdir}/Microsoft.DotNet.PlatformAbstractions.dll", AppContext.BaseDirectory, true); @@ -193,16 +210,23 @@ class Program var statements = code_main.Statements; statements.Add (new CodeVariableDeclarationStatement (typeof (int), "nrun", new CodePrimitiveExpression (0))); statements.Add (new CodeVariableDeclarationStatement (typeof (int), "nfailed", new CodePrimitiveExpression (0))); + statements.Add (new CodeVariableDeclarationStatement (typeof (int), "nskip", new CodePrimitiveExpression (0))); + + int nskipped = 0; var filters = cmdline.Project.Filters; foreach (XunitTestCase tc in sink.TestCases) { var m = ((ReflectionMethodInfo)tc.Method).MethodInfo; //Console.WriteLine ("" + m.ReflectedType + " " + m + " " + (tc.TestMethodArguments == null)); var t = m.ReflectedType; - if (t.IsGenericType) + if (t.IsGenericType) { + nskipped ++; continue; - if (!filters.Filter (tc)) + } + if (!filters.Filter (tc)) { + nskipped ++; continue; + } var cases = tc_data [tc]; @@ -211,9 +235,9 @@ class Program string typename = GetTypeName (t); string msg; if (cases.Count > 1) - msg = $"{typename}:{m.Name}[{caseindex}]..."; + msg = $"{typename}.{m.Name}[{caseindex}] ..."; else - msg = $"{typename}:{m.Name}..."; + msg = $"{typename}.{m.Name} ..."; caseindex ++; statements.Add (new CodeMethodInvokeExpression (new CodeTypeReferenceExpression ("Console"), "WriteLine", new CodeExpression [] { new CodePrimitiveExpression (msg) })); statements.Add (new CodeAssignStatement (new CodeVariableReferenceExpression ("nrun"), new CodeBinaryOperatorExpression (new CodeVariableReferenceExpression ("nrun"), CodeBinaryOperatorType.Add, new CodePrimitiveExpression (1)))); @@ -225,6 +249,7 @@ class Program } if (!m.IsPublic) { // FIXME: + nskipped ++; } else { CodeMethodInvokeExpression call; @@ -251,7 +276,24 @@ class Program } } - //w.WriteLine ("\t\tConsole.WriteLine (\"RUN: \" + nrun + \", FAILED: \" + nfailed);"); + statements.Add (new CodeMethodInvokeExpression (new CodeTypeReferenceExpression ("Console"), "WriteLine", new CodeExpression [] { + new CodeBinaryOperatorExpression ( + new CodePrimitiveExpression ("RUN: "), + CodeBinaryOperatorType.Add, + new CodeVariableReferenceExpression ("nrun")) + })); + statements.Add (new CodeMethodInvokeExpression (new CodeTypeReferenceExpression ("Console"), "WriteLine", new CodeExpression [] { + new CodeBinaryOperatorExpression ( + new CodePrimitiveExpression ("FAILURES: "), + CodeBinaryOperatorType.Add, + new CodeVariableReferenceExpression ("nfailed")) + })); + statements.Add (new CodeMethodInvokeExpression (new CodeTypeReferenceExpression ("Console"), "WriteLine", new CodeExpression [] { + new CodeBinaryOperatorExpression ( + new CodePrimitiveExpression ("SKIPPED: "), + CodeBinaryOperatorType.Add, + new CodePrimitiveExpression (nskipped)) + })); statements.Add (new CodeMethodReturnStatement (new CodePrimitiveExpression (0))); var provider = new CSharpCodeProvider (); diff --git a/netcore/gen-xunit-runner/README.md b/netcore/gen-xunit-runner/README.md index 6ef0cc152a3..0a05d09308e 100644 --- a/netcore/gen-xunit-runner/README.md +++ b/netcore/gen-xunit-runner/README.md @@ -8,6 +8,11 @@ This is a small netcore app to convert a corefx test assembly into a console app dotnet run ../runner.cs ~/git/corefx/ ~/git/corefx//artifacts/bin/System.Runtime.Tests/netcoreapp-Unix-Debug/System.Runtime.Tests.dll -notrait category=nonosxtests -notrait category=failing -notrait category=Outerloop -stoponfail ``` +There is support for response files, i.e. +``` +dotnet run ../runner.cs ~/git/corefx/ ~/git/corefx//artifacts/bin/System.Runtime.Tests/netcoreapp-Unix-Debug/System.Runtime.Tests.dll @excludes.rsp +``` + # Notes - If xunit can't laod a trait discoverer assembly, it silently ignores the error. -- 2.11.4.GIT