Accessing function in anonymous namespace from a unit test #16517

issue davereikher opened this issue on August 1, 2019
  1. davereikher commented at 8:46 AM on August 1, 2019: contributor

    Looking at script/descriptor.cpp, and the associated test file descriptor_tests.cpp, much of the code in descriptor.cpp is inside an anonymous namespace (AN). If I'm not mistaken, this makes functions accessible only within the translation unit corresponding to the source file they're defined in. Functions that are used in the test in descriptor_tests.cpp (such as the Parse function) are outside of the AN. I would like to use the DescriptorChecksum function from descriptor.cpp in a unit test, but it's inside the AN and thus inaccessible from descriptor_tests.cpp. I currently see three options:

    • #include "descriptor.cpp" at the top of descriptor_tests.cpp, which is ugly
    • Move the DescriptorChecksum function outside of the AN.
    • Leave it alone and find something else to unit test

    What's the best way to approach this?

    Also - a lot of the code is inside ANs. Is there a special reason for this? Wouldn't it make sense to gradually move the code outside of ANs to make it more accessible to unit tests?

  2. fanquake added the label Questions and Help on Aug 1, 2019
  3. fanquake added the label Tests on Aug 1, 2019
  4. MarcoFalke commented at 4:44 PM on August 1, 2019: member

    Generally we move the function to the header for testing. Though, for some really low-level functions we don't do that because they are implicitly tested through higher-level functions. Let me know if you have more questions.

  5. MarcoFalke closed this on Aug 1, 2019

  6. MarcoFalke locked this on Dec 16, 2021

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: 2026-04-26 06:14 UTC

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