From 65253f61214f7458b38c147de310959898358cab Mon Sep 17 00:00:00 2001 From: Vladiwostok <55026261+Vladiwostok@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:09:33 +0300 Subject: [PATCH] Fail unittests on DMD parsing errors (#154) --- src/dscanner/analysis/helpers.d | 7 ++++++- src/dscanner/analysis/rundmd.d | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/dscanner/analysis/helpers.d b/src/dscanner/analysis/helpers.d index e5780da..1c2ee2a 100644 --- a/src/dscanner/analysis/helpers.d +++ b/src/dscanner/analysis/helpers.d @@ -20,10 +20,10 @@ import dsymbol.modulecache : ModuleCache; import std.experimental.allocator; import std.experimental.allocator.mallocator; -import dmd.parse : Parser; import dmd.astbase : ASTBase; import dmd.astcodegen; import dmd.frontend; +import dmd.parse : Parser; S between(S)(S value, S before, S after) if (isSomeString!S) { @@ -390,6 +390,7 @@ void assertAnalyzerWarningsDMD(string code, const StaticAnalysisConfig config, b import std.stdio : File; import dscanner.analysis.rundmd : analyzeDmd, parseDmdModule; import dscanner.utils : getModuleName; + import dmd.globals : global; auto testFileName = "test.d"; File f = File(testFileName, "w"); @@ -403,6 +404,10 @@ void assertAnalyzerWarningsDMD(string code, const StaticAnalysisConfig config, b f.close(); auto dmdModule = parseDmdModule(file, code); + + if (global.errors > 0) + throw new AssertError("Failed to parse DMD module", file); + if (semantic) dmdModule.fullSemantic(); diff --git a/src/dscanner/analysis/rundmd.d b/src/dscanner/analysis/rundmd.d index eecbfc0..06d46b5 100644 --- a/src/dscanner/analysis/rundmd.d +++ b/src/dscanner/analysis/rundmd.d @@ -85,6 +85,7 @@ private void setupDmd() global.path = Strings(); global.path.push(dmdDirPath.ptr); global.path.push(druntimeDirPath.ptr); + global.errors = 0; initDMD(); }