|
35 | 35 | #include <algorithm> |
36 | 36 | #include <cstdio> |
37 | 37 | #include <cstdlib> |
| 38 | +#include <fstream> |
38 | 39 | #include <list> |
39 | 40 | #include <string> |
40 | 41 | #include <unordered_set> |
@@ -100,6 +101,10 @@ class TestCppcheck : public TestFixture { |
100 | 101 | TEST_CASE(getDumpFileContentsLibrary); |
101 | 102 | TEST_CASE(checkPlistOutput); |
102 | 103 | TEST_CASE(premiumResultsCache); |
| 104 | + TEST_CASE(addonScriptHash); |
| 105 | + TEST_CASE(addonJsonHash); |
| 106 | + TEST_CASE(addonArgsHash); |
| 107 | + TEST_CASE(addonQuotedArgsHash); |
103 | 108 | TEST_CASE(purgedConfiguration); |
104 | 109 | TEST_CASE(recheckInclude); |
105 | 110 | } |
@@ -612,6 +617,68 @@ class TestCppcheck : public TestFixture { |
612 | 617 | ASSERT(hash1 != hash2); |
613 | 618 | } |
614 | 619 |
|
| 620 | + void addonHashInternal(AddonInfo addon, const ScopedFile& file) const |
| 621 | + { |
| 622 | + Settings settings; |
| 623 | + Suppressions supprs; |
| 624 | + ErrorLogger2 errorLogger; |
| 625 | + |
| 626 | + std::vector<std::string> files; |
| 627 | + |
| 628 | + const char code[] = "void f();\nint x;\n"; |
| 629 | + simplecpp::TokenList tokens(code, files, "m1.c"); |
| 630 | + |
| 631 | + Preprocessor preprocessor(tokens, settings, errorLogger, Standards::Language::C); |
| 632 | + ASSERT(preprocessor.loadAllIncludes(files)); |
| 633 | + |
| 634 | + addon.name = "testaddon"; |
| 635 | + settings.addons.insert(addon.name); |
| 636 | + settings.addonInfos.push_back(std::move(addon)); |
| 637 | + settings.addonInfos.back().initContentHash(); |
| 638 | + |
| 639 | + CppCheck check(settings, supprs, errorLogger, nullptr, false, {}); |
| 640 | + const size_t hash1 = check.calculateHash(preprocessor); |
| 641 | + |
| 642 | + settings.addonInfos.back().initContentHash(); |
| 643 | + ASSERT_EQUALS(hash1, check.calculateHash(preprocessor)); |
| 644 | + |
| 645 | + { |
| 646 | + std::ofstream of(file.path()); |
| 647 | + of << "changed content\n"; |
| 648 | + } |
| 649 | + settings.addonInfos.back().initContentHash(); |
| 650 | + // cppcheck-suppress knownConditionTrueFalse |
| 651 | + ASSERT(hash1 != check.calculateHash(preprocessor)); |
| 652 | + } |
| 653 | + |
| 654 | + void addonScriptHash() const { |
| 655 | + ScopedFile addon_script("testaddon.py", "# addon v1\n"); |
| 656 | + AddonInfo addon; |
| 657 | + addon.scriptFile = addon_script.path(); |
| 658 | + addonHashInternal(addon, addon_script); |
| 659 | + } |
| 660 | + |
| 661 | + void addonJsonHash() const { |
| 662 | + ScopedFile addon_config("testaddon.json", "{ \"script\": \"x.py\" }\n"); |
| 663 | + AddonInfo addon; |
| 664 | + addon.jsonFile = addon_config.path(); |
| 665 | + addonHashInternal(addon, addon_config); |
| 666 | + } |
| 667 | + |
| 668 | + void addonArgsHash() const { |
| 669 | + ScopedFile rule_texts("testrules.txt", "rule v1\n"); |
| 670 | + AddonInfo addon; |
| 671 | + addon.args = "--rule-texts=" + rule_texts.path(); |
| 672 | + addonHashInternal(addon, rule_texts); |
| 673 | + } |
| 674 | + |
| 675 | + void addonQuotedArgsHash() const { |
| 676 | + ScopedFile rule_texts("test rules.txt", "rule v1\n"); |
| 677 | + AddonInfo addon; |
| 678 | + addon.args = "--rule-texts=\"" + rule_texts.path() + "\""; |
| 679 | + addonHashInternal(addon, rule_texts); |
| 680 | + } |
| 681 | + |
615 | 682 | void purgedConfiguration() const |
616 | 683 | { |
617 | 684 | ScopedFile test_file("test.cpp", |
|
0 commit comments