From 02384a926aa848500dd2d575cc5b033ba7fe0a77 Mon Sep 17 00:00:00 2001 From: Vladiwostok <55026261+Vladiwostok@users.noreply.github.com> Date: Sun, 29 Sep 2024 17:08:38 +0300 Subject: [PATCH] Respect "skip unittest" user configuration (#139) --- .../analysis/explicitly_annotated_unittests.d | 3 +++ src/dscanner/analysis/has_public_example.d | 3 +++ .../analysis/label_var_same_name_check.d | 23 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/dscanner/analysis/explicitly_annotated_unittests.d b/src/dscanner/analysis/explicitly_annotated_unittests.d index 57702482..db66e7ed 100644 --- a/src/dscanner/analysis/explicitly_annotated_unittests.d +++ b/src/dscanner/analysis/explicitly_annotated_unittests.d @@ -24,6 +24,9 @@ extern(C++) class ExplicitlyAnnotatedUnittestCheck(AST) : BaseAnalyzerDmd { import dmd.astenums : STC; + if (skipTests) + return; + if (!(d.storage_class & STC.safe || d.storage_class & STC.system)) addErrorMessage(cast(ulong) d.loc.linnum, cast(ulong) d.loc.charnum, KEY, MESSAGE); diff --git a/src/dscanner/analysis/has_public_example.d b/src/dscanner/analysis/has_public_example.d index fe5a9102..b8b2e34d 100644 --- a/src/dscanner/analysis/has_public_example.d +++ b/src/dscanner/analysis/has_public_example.d @@ -47,6 +47,9 @@ extern (C++) class HasPublicExampleCheck(AST) : BaseAnalyzerDmd override void visit(AST.UnitTestDeclaration unitTestDecl) { + if (skipTests) + return; + if (unitTestDecl.comment() !is null) isDocumented = true; } diff --git a/src/dscanner/analysis/label_var_same_name_check.d b/src/dscanner/analysis/label_var_same_name_check.d index b891d6c7..3fc1d893 100644 --- a/src/dscanner/analysis/label_var_same_name_check.d +++ b/src/dscanner/analysis/label_var_same_name_check.d @@ -33,7 +33,6 @@ extern (C++) class LabelVarNameCheck(AST) : BaseAnalyzerDmd mixin FunctionVisit!(AST.FuncDeclaration); mixin FunctionVisit!(AST.TemplateDeclaration); - mixin FunctionVisit!(AST.UnitTestDeclaration); mixin FunctionVisit!(AST.FuncLiteralDeclaration); mixin AggregateVisit!(AST.ClassDeclaration); @@ -134,6 +133,28 @@ extern (C++) class LabelVarNameCheck(AST) : BaseAnalyzerDmd popAggregateName(); } + override void visit(AST.UnitTestDeclaration unitTestDecl) + { + if (skipTests) + return; + + auto oldIsInFunction = isInFunction; + auto oldIsInLocalFunction = isInLocalFunction; + + pushScope(); + + if (isInFunction) + isInLocalFunction = true; + else + isInFunction = true; + + super.visit(unitTestDecl); + popScope(); + + isInFunction = oldIsInFunction; + isInLocalFunction = oldIsInLocalFunction; + } + private: extern (D) Thing[string][] stack; int conditionalDepth;