lint: convert lint-tests.sh to python #24815

pull KevinMusgrave wants to merge 1 commits into bitcoin:master from KevinMusgrave:lint-tests-python-port changing 2 files +87 −35
  1. KevinMusgrave commented at 10:05 pm on April 9, 2022: contributor
  2. KevinMusgrave renamed this:
    Converted lint-tests.sh to python
    lint: converted lint-tests.sh to python
    on Apr 9, 2022
  3. KevinMusgrave force-pushed on Apr 9, 2022
  4. KevinMusgrave renamed this:
    lint: converted lint-tests.sh to python
    lint: convert lint-tests.sh to python
    on Apr 9, 2022
  5. DrahtBot added the label Tests on Apr 9, 2022
  6. KevinMusgrave commented at 11:59 am on April 11, 2022: contributor
    Maybe I should replace grep, cut, sort, and uniq with python functions
  7. KevinMusgrave force-pushed on Apr 11, 2022
  8. KevinMusgrave force-pushed on Apr 11, 2022
  9. KevinMusgrave commented at 10:19 pm on April 11, 2022: contributor
    Ok I converted those functions to python, so the only non-python call is git grep.
  10. KevinMusgrave force-pushed on Apr 11, 2022
  11. KevinMusgrave force-pushed on Apr 11, 2022
  12. in test/lint/lint-tests.py:3 in 285ee4b00c outdated
    0@@ -0,0 +1,76 @@
    1+#!/usr/bin/env python3
    2+#
    3+# Copyright (c) 2018 The Bitcoin Core developers
    


    vincenzopalazzo commented at 11:33 pm on April 11, 2022:
    0# Copyright (c) 2018-2022 The Bitcoin Core developers
    

    KevinMusgrave commented at 2:12 pm on April 13, 2022:
    Fixed
  13. KevinMusgrave force-pushed on Apr 13, 2022
  14. KevinMusgrave commented at 2:37 pm on April 13, 2022: contributor

    Below are example outputs, before and after the change. The only difference is that the new version adds a newline after the “matching names” test, which I think improves readability.

    Before (lint-tests.sh):

     0The test suite in file src/test/foo_tests.cpp should be named
     1"foo_tests". Please make sure the following test suites follow
     2that convention:
     3
     4src/test/banman_tests.cpp:BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup)
     5src/test/bip32_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
     6src/test/blockchain_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
     7src/test/blockencodings_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, RegTestingSetup)
     8Test suite names must be unique. The following test suite names
     9appear to be used more than once:
    10
    11addrman_tests
    12base58_tests
    

    After (lint-tests.py):

     0The test suite in file src/test/foo_tests.cpp should be named
     1"foo_tests". Please make sure the following test suites follow
     2that convention:
     3
     4src/test/banman_tests.cpp:BOOST_FIXTURE_TEST_SUITE(addrman_tests, BasicTestingSetup)
     5src/test/bip32_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
     6src/test/blockchain_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, BasicTestingSetup)
     7src/test/blockencodings_tests.cpp:BOOST_FIXTURE_TEST_SUITE(base58_tests, RegTestingSetup)
     8
     9Test suite names must be unique. The following test suite names
    10appear to be used more than once:
    11
    12addrman_tests
    13base58_tests
    
  15. in test/lint/lint-tests.py:26 in b4125057ba outdated
    21+        r"^BOOST_FIXTURE_TEST_SUITE\(",
    22+        "--",
    23+        "src/test/**.cpp",
    24+        "src/wallet/test/**.cpp",
    25+    ]
    26+    return subprocess.run(command, stdout=subprocess.PIPE, universal_newlines=True)
    


    laanwj commented at 5:45 pm on April 13, 2022:
    Would prefer to use check_output here. This would make the script automatically fail if the git grep returns an error status. It also autmatically does stdout=PIPE and returns stdout.

    KevinMusgrave commented at 6:24 pm on April 13, 2022:
    Done
  16. KevinMusgrave force-pushed on Apr 13, 2022
  17. KevinMusgrave force-pushed on Apr 13, 2022
  18. Eunoia1729 commented at 10:22 pm on April 13, 2022: contributor
    utACk Not sure but is it a good practise to leave links in the code ?
  19. KevinMusgrave commented at 10:28 pm on April 13, 2022: contributor
    When I grab a snippet from stackoverflow, I like to leave a link to credit the author but also in case I want to see the original answer again.
  20. Converted lint-tests.sh to python
    Use raw string
    
    Use re.search instead of grep in check_matching_test_names
    
    Replaced bash commands in check_unique_test_names with python commands
    
    Use set and sort output
    
    Use set comprehension
    
    Use .splitlines()
    
    Call grep_boost_fixture_test_suite once
    
    splitlines() once
    
    Fixed copyright date
    
    Use check_output() instead of run()
    
    add encoding='utf8'
    
    Use clearer code for getting duplicates
    ae0e06a439
  21. in test/lint/lint-tests.py:51 in 21b967a67d outdated
    46+
    47+
    48+def check_unique_test_names(test_suite_list):
    49+    output = [re.search(r"\((.*?),", x) for x in test_suite_list]
    50+    output = [x.group(1) for x in output if x is not None]
    51+    # find duplicates, see: https://stackoverflow.com/a/9835819
    


    MarcoFalke commented at 11:11 am on April 15, 2022:
    This is pretty hard to read and the answer actually recommends against using the snippet.

    MarcoFalke commented at 11:11 am on April 15, 2022:
    This is pretty hard to read and the answer actually recommends against using the snippet.

    KevinMusgrave commented at 1:41 pm on April 15, 2022:
    I assume you mean this output = {x for x in output if x in seen or seen.add(x)}. I thought the comment makes it clear what it does, but I can convert it to a for loop anyway.

    KevinMusgrave commented at 2:16 pm on April 15, 2022:
    I changed it now

    KevinMusgrave commented at 2:16 pm on April 15, 2022:
    Looks like an accidental duplicate review
  22. KevinMusgrave force-pushed on Apr 15, 2022
  23. laanwj commented at 5:27 pm on April 25, 2022: member
    Tested ACK ae0e06a439e09a7e24dd6198591a588c8df2d529
  24. laanwj merged this on Apr 25, 2022
  25. laanwj closed this on Apr 25, 2022

  26. sidhujag referenced this in commit ea3961c0ac on Apr 26, 2022
  27. DrahtBot locked this on Apr 25, 2023

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-05 19:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me