Skip to content

Commit c5867e7

Browse files
committed
fixed issue causing C# tests to fail
1 parent 005c979 commit c5867e7

2 files changed

Lines changed: 32 additions & 11 deletions

File tree

‎src/main/java/com/dtsx/docs/core/runner/drivers/impls/CSharpDriver.java‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import java.util.List;
1919
import java.util.Map;
2020
import java.util.function.Function;
21-
import java.util.regex.Pattern;
2221

2322
public class CSharpDriver extends ClientDriver {
2423
public CSharpDriver(String artifact) {
@@ -51,9 +50,28 @@ public Path setupExecutionEnvironment(BaseScriptRunnerCtx ctx, ExecutionEnvironm
5150

5251
@Override
5352
public String preprocessScript(BaseScriptRunnerCtx ignoredCtx, String content, @TestFileModifierFlags int mods) {
54-
return Pattern.compile("^public\\s+class\\s+\\w+", Pattern.MULTILINE)
55-
.matcher(content)
56-
.replaceFirst("public class Example");
53+
val mainIndex = content.indexOf("Main(");
54+
55+
if (mainIndex == -1) {
56+
throw new RunException("Main method not found in C# script");
57+
}
58+
59+
val classIndex = content.lastIndexOf("\npublic class ", mainIndex);
60+
61+
if (classIndex == -1) {
62+
throw new RunException("Public class declaration not found before Main method in C# script");
63+
}
64+
65+
val nameStart = classIndex + "\npublic class ".length();
66+
var nameEnd = nameStart;
67+
68+
while (nameEnd < content.length() && Character.isLetterOrDigit(content.charAt(nameEnd))) {
69+
nameEnd++;
70+
}
71+
72+
return content.substring(0, nameStart)
73+
+ "Example"
74+
+ content.substring(nameEnd);
5775
}
5876

5977
@Override

‎src/main/java/com/dtsx/docs/core/runner/tests/strategies/test/CompilesTestStrategy.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,19 @@ private void runSingleTest(TestRoot testRoot, Map<ClientLanguage, Map<Path, Test
7878
return;
7979
}
8080

81-
execEnv.withTestFileCopied(driver, path, mkPlaceholders(testRoot), TestFileModifiers.NONE, () -> {
82-
val res = driver.compileScript(ctx, execEnv);
81+
try {
82+
val outcome = execEnv.withTestFileCopied(driver, path, mkPlaceholders(testRoot), TestFileModifiers.NONE, () -> {
83+
val res = driver.compileScript(ctx, execEnv);
8384

84-
val outcome = (res.notOk())
85-
? new TestOutcome.FailedToCompile(res.output()).alsoLog(testRoot, lang, res.output())
86-
: TestOutcome.Passed.INSTANCE;
85+
return (res.notOk())
86+
? new TestOutcome.FailedToCompile(res.output()).alsoLog(testRoot, lang, res.output())
87+
: TestOutcome.Passed.INSTANCE;
88+
});
8789

8890
outcomes.get(lang).put(path, outcome);
89-
return null;
90-
});
91+
} catch (Exception e) {
92+
outcomes.get(lang).put(path, new TestOutcome.Errored(e).alsoLog(testRoot, lang));
93+
}
9194
}
9295

9396
private Placeholders mkPlaceholders(TestRoot testRoot) {

0 commit comments

Comments
 (0)