From 3293f7e5b0a630c2672d0811496663d674a7109c Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Thu, 2 Jan 2025 13:23:17 -0800 Subject: [PATCH 1/2] Predictable test run condition processing --- Src/IronPythonTest/Cases/CaseGenerator.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Src/IronPythonTest/Cases/CaseGenerator.cs b/Src/IronPythonTest/Cases/CaseGenerator.cs index fea1754ed..b50e7b5b1 100644 --- a/Src/IronPythonTest/Cases/CaseGenerator.cs +++ b/Src/IronPythonTest/Cases/CaseGenerator.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Collections.Specialized; using System.Data; using System.IO; using System.Runtime.InteropServices; @@ -105,7 +106,7 @@ protected bool ConditionMatched(string condition) { private bool EvaluateExpression(string expression) { var dummy = new DataTable(); string filter = expression; - var replacements = new Dictionary() { + var replacements = new OrderedDictionary() { // variables { "$(IS_NETCOREAPP)", IronPython.Runtime.ClrModule.IsNetCoreApp.ToString() }, { "$(IS_NETSTANDARD)", IronPython.Runtime.ClrModule.TargetFramework.StartsWith(".NETStandard", StringComparison.Ordinal).ToString() }, @@ -119,20 +120,20 @@ private bool EvaluateExpression(string expression) { // operators { "==", "=" }, { "||", "OR" }, + { "\"", "'" }, // replace double quotes before double-double quotes { "\"\"", "\"" }, - { "\"", "'" }, { "&&", "AND" }, - { "!=", "<>" } + { "!=", "<>" }, }; - foreach (var replacement in replacements) { - expression = expression.Replace(replacement.Key, replacement.Value); + foreach (DictionaryEntry replacement in replacements) { + expression = expression.Replace((string)replacement.Key, replacement.Value?.ToString()); } try { object res = dummy.Compute(expression, null); - if (res is bool) { - return (bool)res; + if (res is bool result) { + return result; } } catch (EvaluateException ex) { if (ex.Message.StartsWith("The expression contains undefined function call", StringComparison.Ordinal)) From 17f04fdc382315d4c2e23c8f50b6495d25c9e591 Mon Sep 17 00:00:00 2001 From: Pavel Koneski Date: Thu, 2 Jan 2025 13:42:57 -0800 Subject: [PATCH 2/2] Support variable $(FRAMEWORK) in test run conditions --- Src/IronPythonTest/Cases/CaseGenerator.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Src/IronPythonTest/Cases/CaseGenerator.cs b/Src/IronPythonTest/Cases/CaseGenerator.cs index b50e7b5b1..b1f39575b 100644 --- a/Src/IronPythonTest/Cases/CaseGenerator.cs +++ b/Src/IronPythonTest/Cases/CaseGenerator.cs @@ -108,6 +108,7 @@ private bool EvaluateExpression(string expression) { string filter = expression; var replacements = new OrderedDictionary() { // variables + { "$(FRAMEWORK)", IronPython.Runtime.ClrModule.TargetFramework }, { "$(IS_NETCOREAPP)", IronPython.Runtime.ClrModule.IsNetCoreApp.ToString() }, { "$(IS_NETSTANDARD)", IronPython.Runtime.ClrModule.TargetFramework.StartsWith(".NETStandard", StringComparison.Ordinal).ToString() }, { "$(IS_MONO)", IronPython.Runtime.ClrModule.IsMono.ToString() },