diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2020-04-16 18:25:53 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-16 15:25:53 -0700 |
| commit | 12b30afb24ac03d69f091f18c25ed2bbefae1acd (patch) | |
| tree | fd5dc0c512c707c46bd3640f604f308a461a6bda /tools | |
| parent | b5a531738baa1e856b15bb3dffdbea9a1ee5cc82 (diff) | |
Workaround for matching of dxc diagnostics (#1324)
* Specialized handling for comparison of dxc output that ignores line/column numbers.
* Simplify areAllEqualWithSplit.
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/slang-test/slang-test-main.cpp | 96 |
1 files changed, 63 insertions, 33 deletions
diff --git a/tools/slang-test/slang-test-main.cpp b/tools/slang-test/slang-test-main.cpp index d72144856..da03d67fe 100644 --- a/tools/slang-test/slang-test-main.cpp +++ b/tools/slang-test/slang-test-main.cpp @@ -977,6 +977,37 @@ static UnownedStringSlice _removeDiagnosticPrefix(const UnownedStringSlice& pref } } +static bool _isUnsignedInteger(const UnownedStringSlice& a) +{ + const char* end = a.end(); + for (const char* cur = a.begin(); cur < end; ++cur) + { + if (!(*cur >= '0' && *cur <= '9')) + { + return false; + } + } + return true; +} + +static bool _isDXCLineSplitEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) +{ + return a == b || (_isUnsignedInteger(a.trim()) && _isUnsignedInteger(b.trim())); +} + +// Returns true if a and b are output from dxc (prefixed with dxc:. +// Ignores line number/column number differences from the dxc specific line format. +static bool _isDXCLineEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) +{ + // We are going to ignore the line number/column number. + // To do this if we find any sub strings inbetween : that are just all digits we'll assume it's a line number/column number + // and ignore + + // dxc: tests/cross-compile/dxc-error.hlsl:9:2: error: use of undeclared identifier 'gOutputBuffer' + const UnownedStringSlice dxcPrefix = UnownedStringSlice::fromLiteral("dxc:"); + return a.startsWith(dxcPrefix) && b.startsWith(dxcPrefix) && StringUtil::areAllEqualWithSplit(a, b, ':', _isDXCLineSplitEqual); +} + static bool _isLineEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) { if (a == b) @@ -1004,50 +1035,49 @@ static bool _isLineEqual(const UnownedStringSlice& a, const UnownedStringSlice& } } - return false; + return _isDXCLineEqual(a, b); } -static bool _areResultsEqual(TestOptions::Type type, const String& a, const String& b) +static bool _areDiagnosticsEqual(const UnownedStringSlice& a, const UnownedStringSlice& b) { - switch (type) + // If they are identical we are done + if (a == b) { - case TestOptions::Type::Diagnostic: - { - // If they are identical we are done - if (a == b) - { - return true; - } - - // Okay we are going to go line by line - // If the lines are equal thats ok. - // If they are not.. we will check if the only difference is line numbers from the stdlib + return true; + } - List<UnownedStringSlice> linesA; - List<UnownedStringSlice> linesB; + // Okay we are going to go line by line + // If the lines are equal thats ok. + // If they are not.. we will check if the only difference is line numbers from the stdlib - StringUtil::calcLines(a.getUnownedSlice(), linesA); - StringUtil::calcLines(b.getUnownedSlice(), linesB); + List<UnownedStringSlice> linesA; + List<UnownedStringSlice> linesB; - if (linesA.getCount() != linesB.getCount()) - { - return false; - } + StringUtil::calcLines(a, linesA); + StringUtil::calcLines(b, linesB); - for (Index i = 0; i < linesA.getCount(); ++i) - { - if (!_isLineEqual(linesA[i], linesB[i])) - { - return false; - } - } + if (linesA.getCount() != linesB.getCount()) + { + return false; + } - return true; - } - case TestOptions::Type::Normal: + for (Index i = 0; i < linesA.getCount(); ++i) + { + if (!_isLineEqual(linesA[i], linesB[i])) { - return a == b; + return false; } + } + + return true; +} + +static bool _areResultsEqual(TestOptions::Type type, const String& a, const String& b) +{ + switch (type) + { + case TestOptions::Type::Diagnostic: return _areDiagnosticsEqual(a.getUnownedSlice(), b.getUnownedSlice()); + case TestOptions::Type::Normal: return a == b; default: { SLANG_ASSERT(!"Unknown test type"); |
