diff mbox series

[04/16] support/testing: test check-package ignore list

Message ID 20220724054912.2354219-5-ricardo.martincoski@gmail.com
State Changes Requested
Headers show
Series Preventing style regressions using check-package | expand

Commit Message

Ricardo Martincoski July 24, 2022, 5:49 a.m. UTC
Extend test_check_package to also check the ignore list functionality.
Check:
- the entries in the ignore list use relative path;
- an entry in the ignore list actually ignores the warning;
- an outdated entry in the ignore list generates a warning by its own,
  preventing the ignoring list to grow indefinitely.

For this to work, add 3 test fixtures, listing entries for an
pre-existing file in the br2-external used in the test.

Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
---
 .../utils/br2-external/.checkpackageignore    |  1 +
 .../br2-external/package/.checkpackageignore  |  1 +
 .../package/.checkpackageignore_outdated      |  1 +
 .../testing/tests/utils/test_check_package.py | 31 +++++++++++++++++++
 4 files changed, 34 insertions(+)
 create mode 100644 support/testing/tests/utils/br2-external/.checkpackageignore
 create mode 100644 support/testing/tests/utils/br2-external/package/.checkpackageignore
 create mode 100644 support/testing/tests/utils/br2-external/package/.checkpackageignore_outdated
diff mbox series

Patch

diff --git a/support/testing/tests/utils/br2-external/.checkpackageignore b/support/testing/tests/utils/br2-external/.checkpackageignore
new file mode 100644
index 0000000000..efb7680173
--- /dev/null
+++ b/support/testing/tests/utils/br2-external/.checkpackageignore
@@ -0,0 +1 @@ 
+package/external/external.mk PackageHeader
diff --git a/support/testing/tests/utils/br2-external/package/.checkpackageignore b/support/testing/tests/utils/br2-external/package/.checkpackageignore
new file mode 100644
index 0000000000..5f4a5e1187
--- /dev/null
+++ b/support/testing/tests/utils/br2-external/package/.checkpackageignore
@@ -0,0 +1 @@ 
+external/external.mk PackageHeader
diff --git a/support/testing/tests/utils/br2-external/package/.checkpackageignore_outdated b/support/testing/tests/utils/br2-external/package/.checkpackageignore_outdated
new file mode 100644
index 0000000000..1df59f3bed
--- /dev/null
+++ b/support/testing/tests/utils/br2-external/package/.checkpackageignore_outdated
@@ -0,0 +1 @@ 
+external/external.mk Indent NewlineAtEof PackageHeader
diff --git a/support/testing/tests/utils/test_check_package.py b/support/testing/tests/utils/test_check_package.py
index c70ba02324..f21b9e939f 100644
--- a/support/testing/tests/utils/test_check_package.py
+++ b/support/testing/tests/utils/test_check_package.py
@@ -75,6 +75,12 @@  class TestCheckPackage(unittest.TestCase):
         generated = int(stderr[1].split()[0])
         self.assertGreater(generated, 0)
 
+    def assert_no_warnings_generated_for_file(self, stderr):
+        """Infer from check-package stderr if no warning was generated and fail otherwise."""
+        self.assertIn("warnings generated", stderr[1], stderr)
+        generated = int(stderr[1].split()[0])
+        self.assertEqual(generated, 0)
+
     def test_run(self):
         """Test the various ways the script can be called in a simple top to
         bottom sequence."""
@@ -201,3 +207,28 @@  class TestCheckPackage(unittest.TestCase):
         self.assert_file_was_processed(m)
         self.assert_warnings_generated_for_file(m)
         self.assertIn("{}:1: should be 80 hashes (http://nightly.buildroot.org/#writing-rules-mk)".format(abs_file), w)
+
+        # br2-external with ignore list
+        topdir_path = infra.filepath("tests/utils/br2-external")
+        topdir_file = os.path.join(topdir_path, "package/external/external.mk")
+        subdir_path = infra.filepath("tests/utils/br2-external/package")
+        subdir_file = os.path.join(subdir_path, "external/external.mk")
+
+        w, m = call_script(["check-package", "--ignore-list=./.checkpackageignore", "-b", topdir_file],
+                           self.WITH_UTILS_IN_PATH, topdir_path)
+        self.assert_file_was_processed(m)
+        self.assert_no_warnings_generated_for_file(m)
+
+        w, m = call_script(["check-package", "--ignore-list=./.checkpackageignore", "-b", subdir_file],
+                           self.WITH_UTILS_IN_PATH, subdir_path)
+        self.assert_file_was_processed(m)
+        self.assert_no_warnings_generated_for_file(m)
+
+        w, m = call_script(["check-package", "--ignore-list=./.checkpackageignore_outdated", "-b", subdir_file],
+                           self.WITH_UTILS_IN_PATH, subdir_path)
+        self.assert_file_was_processed(m)
+        self.assert_warnings_generated_for_file(m)
+        self.assertIn("{}:0: Indent was expected to fail, did you fixed the file and forgot to update .checkpackageignore?"
+                      .format(subdir_file), w)
+        self.assertIn("{}:0: NewlineAtEof was expected to fail, did you fixed the file and forgot to update .checkpackageignore?"
+                      .format(subdir_file), w)