From 0dafa83a59f49f78d3dca0c44f5bdc1ad812d390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Wed, 26 Mar 2025 09:08:55 +0000 Subject: [PATCH 1/2] Make it possible to input arguments to the TestRunner after starting it --- TestRunner/Program.cs | 56 ++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/TestRunner/Program.cs b/TestRunner/Program.cs index d010669c..74e69e49 100644 --- a/TestRunner/Program.cs +++ b/TestRunner/Program.cs @@ -44,45 +44,47 @@ static void Main(string[] args) { LoadAllTestAssemblies(); - if (args.Length == 0) + + while (args.Length == 0 || !m_TestMethods.ContainsKey(args[0])) { - Console.WriteLine("Please provide a filter for the methods you want to run. This can be either the name of the method or its namespace (after 'BH.Test')"); - return; + if (args.Length == 0) + Console.WriteLine("Please provide a filter for the methods you want to run. This can be either the name of the method or its namespace (after 'BH.Test')"); + else + Console.WriteLine("Cannot find any test matching " + args[0]); + + Console.WriteLine($"Avilable methods to run are: {string.Join(", ", m_TestMethods.Keys)}"); + + args = Console.ReadLine().Split(' '); } string key = args[0]; - if (!m_TestMethods.ContainsKey(key)) - { - Console.WriteLine("Cannot find any test matching " + key); - } - else + + foreach (MethodInfo method in m_TestMethods[key]) { - foreach (MethodInfo method in m_TestMethods[key]) + try { - try + object[] parameters = new object[] { }; + if (method.GetParameters().Length == 1) { - object[] parameters = new object[] { }; - if (method.GetParameters().Length == 1) + if (args.Length == 2) { - if (args.Length == 2) - { - parameters = new object[] { System.Convert.ToBoolean(args[1]) }; - } - else if (method.GetParameters()[0].HasDefaultValue) - { - parameters = new object[] { method.GetParameters()[0].DefaultValue }; - } + parameters = new object[] { System.Convert.ToBoolean(args[1]) }; + } + else if (method.GetParameters()[0].HasDefaultValue) + { + parameters = new object[] { method.GetParameters()[0].DefaultValue }; } - TestResult result = method.Invoke(null, parameters) as TestResult; - Console.WriteLine(); - Console.Write(result.FullMessage()); - } - catch (Exception e) - { - Console.WriteLine($"Method {method.Name} failed to run:\n{e.Message}"); } + TestResult result = method.Invoke(null, parameters) as TestResult; + Console.WriteLine(); + Console.Write(result.FullMessage()); + } + catch (Exception e) + { + Console.WriteLine($"Method {method.Name} failed to run:\n{e.Message}"); } } + } From 50e7ca3fc70a3017b6101e205cbb1e43e111e8af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isak=20N=C3=A4slund?= Date: Thu, 3 Apr 2025 12:06:49 +0100 Subject: [PATCH 2/2] Apply suggestions from code review Co-authored-by: Pawel Baran --- TestRunner/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TestRunner/Program.cs b/TestRunner/Program.cs index 74e69e49..d539bc23 100644 --- a/TestRunner/Program.cs +++ b/TestRunner/Program.cs @@ -47,12 +47,12 @@ static void Main(string[] args) while (args.Length == 0 || !m_TestMethods.ContainsKey(args[0])) { - if (args.Length == 0) - Console.WriteLine("Please provide a filter for the methods you want to run. This can be either the name of the method or its namespace (after 'BH.Test')"); - else + if (args.Length != 0) Console.WriteLine("Cannot find any test matching " + args[0]); + + Console.WriteLine("Please provide a filter for the methods you want to run. This can be either the name of the method or its namespace (after 'BH.Test')."); - Console.WriteLine($"Avilable methods to run are: {string.Join(", ", m_TestMethods.Keys)}"); + Console.WriteLine($"Available methods to run are: {string.Join(", ", m_TestMethods.Keys)}"); args = Console.ReadLine().Split(' '); }