Testing Argp tropf ABSTRACT presentation of short helper to more easily test argp 1. Intro 1.1. Argp Argp ⟨https://www.gnu.org/software/libc/manual/ html_node/Argp.html⟩ is one of the more advanced parsers for command‐line arguments out there. As it is part of glibc, it is available on all of the major distributions. You only see it rarely, as most applications don’t care too much about the output of ‐‐help or move large parts of it into their man page. And as Argp is a C‐Library most C++‐devs don’t fancy it too much. Once set up it’s usage is very straight forward, just pass argc and argv directly into Argp and everything will be handled. 1.2. Testing When building applications I often spend a large part of my time checking that the configuration works properly. Part of that is testing that command‐line arguments are parsed correctly and are associated to their internal vari‐ ables. Argp, however, has fairly high (and strange) demands for its inputs. First of all, it requires the typical for‐ mat of argc and argv: While the former is just an integer, the latter is an array of pointers to c‐style strings, i.e. null‐terminated char arrays. Also the memory that argv is pointing to might be overwritten during Argp’s operation, so it has to be re‐initialized for each test case. Finally, the memory must not be on the heap. This means, argv may only point to regions of the stack, otherwise there will be malloc‐errors. 18 April 2021 ‐2‐ 2. Concept The helper class below accepts a string. This will be exploded into a list of words. From there, all words will be stored consecutively separated by null bytes. › Realtabs are not regarded as separator! All data resides on the stack, thus there is a limit for the total number of characters stored (4096 bytes in‐ cluding separator bytes) and a maximum number of arguments (31). 3. Code For usage please have a look at the test code. › argv[0] has to be intialized with the binary name when using w/ argp. 3.1. License This code is licensed under CC0 ⟨http:// creativecommons.org/publicdomain/zero/1.0/⟩ (public domain). 3.2. Full Text download ⟨../blob/argv_helper.cc⟩ › Due to fun quirks of groff, any ' in the code will be displayed as ’ (and produces a syntax er‐ ror when compiled). Just download the files di‐ rectly. 3.3. Tests download ⟨../blob/argv_helper_test.cc⟩ 4. See also • Argp doc ⟨https://www.gnu.org/software/libc/manual/ html_node/Argp.html⟩ • Step by step into Argp ⟨https://nongnu.askapache.com/ argpbook/step‐by‐step‐into‐argp.pdf⟩: best guide for Argp I know; project homepage ⟨http://www.nongnu.org/ argpbook/⟩ 18 April 2021 ‐3‐ • smplxmpp ⟨https://smplxmpp.com/⟩: uses this code • layout of argv ⟨https://web.njit.edu/~sohna/cs288/ hello‐memap.pdf⟩ 18 April 2021