Skip to content

Commit 1cdaedd

Browse files
authored
Improve test run condition expression (#1858)
* Predictable test run condition processing * Support variable $(FRAMEWORK) in test run conditions
1 parent e0bb6ad commit 1cdaedd

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

Src/IronPythonTest/Cases/CaseGenerator.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.Collections;
77
using System.Collections.Generic;
8+
using System.Collections.Specialized;
89
using System.Data;
910
using System.IO;
1011
using System.Runtime.InteropServices;
@@ -105,8 +106,9 @@ protected bool ConditionMatched(string condition) {
105106
private bool EvaluateExpression(string expression) {
106107
var dummy = new DataTable();
107108
string filter = expression;
108-
var replacements = new Dictionary<string, string>() {
109+
var replacements = new OrderedDictionary() {
109110
// variables
111+
{ "$(FRAMEWORK)", IronPython.Runtime.ClrModule.TargetFramework },
110112
{ "$(IS_NETCOREAPP)", IronPython.Runtime.ClrModule.IsNetCoreApp.ToString() },
111113
{ "$(IS_NETSTANDARD)", IronPython.Runtime.ClrModule.TargetFramework.StartsWith(".NETStandard", StringComparison.Ordinal).ToString() },
112114
{ "$(IS_MONO)", IronPython.Runtime.ClrModule.IsMono.ToString() },
@@ -119,20 +121,20 @@ private bool EvaluateExpression(string expression) {
119121
// operators
120122
{ "==", "=" },
121123
{ "||", "OR" },
124+
{ "\"", "'" }, // replace double quotes before double-double quotes
122125
{ "\"\"", "\"" },
123-
{ "\"", "'" },
124126
{ "&&", "AND" },
125-
{ "!=", "<>" }
127+
{ "!=", "<>" },
126128
};
127129

128-
foreach (var replacement in replacements) {
129-
expression = expression.Replace(replacement.Key, replacement.Value);
130+
foreach (DictionaryEntry replacement in replacements) {
131+
expression = expression.Replace((string)replacement.Key, replacement.Value?.ToString());
130132
}
131133

132134
try {
133135
object res = dummy.Compute(expression, null);
134-
if (res is bool) {
135-
return (bool)res;
136+
if (res is bool result) {
137+
return result;
136138
}
137139
} catch (EvaluateException ex) {
138140
if (ex.Message.StartsWith("The expression contains undefined function call", StringComparison.Ordinal))

0 commit comments

Comments
 (0)