all.sh: improve fragile not grep idiom #266

Open
opened 2026-01-09 03:59:43 -06:00 by gilles-peskine-arm · 0 comments
gilles-peskine-arm commented 2026-01-09 03:59:43 -06:00 (Migrated from github.com)

We often check for the absence of a function in a file with the idiom not grep REGEXP FILE[...] in all.sh. The function not is a wrapper around ! that takes care of failing the component if the command exits with the status 0. As noted in https://github.com/Mbed-TLS/mbedtls/pull/10517#discussion_r2675303189 this is fragile: it'll pass if the file doesn't exist.

The goal of this issue is:

  1. Pick a name for a “not grep” function. not_grep is natural but might be a bit misleading since it's not just ! grep.
  2. Define a new function that does what we want. I believe the semantics is: not_grep REGEXP FILE[...] passes if all the files exist and the regexp is not found in any of the files. Note that the files can be expressed as a pattern, and since we use bash with default settings, if the pattern doesn't match any file, it'll remain unexpanded and the function will see it as a file name that doesn't exist.
  3. Systematically replace not grep by the new function in tests/scripts/components-*.sh in all branches.
We often check for the absence of a function in a file with the idiom `not grep REGEXP FILE[...]` in `all.sh`. The function `not` is a wrapper around `!` that takes care of failing the component if the command exits with the status 0. As noted in https://github.com/Mbed-TLS/mbedtls/pull/10517#discussion_r2675303189 this is fragile: it'll pass if the file doesn't exist. The goal of this issue is: 1. Pick a name for a “not grep” function. `not_grep` is natural but might be a bit misleading since it's not just `! grep`. 2. Define a new function that does what we want. I believe the semantics is: `not_grep REGEXP FILE[...]` passes if all the files exist and the regexp is not found in any of the files. Note that the files can be expressed as a pattern, and since we use bash with default settings, if the pattern doesn't match any file, it'll remain unexpanded and the function will see it as a file name that doesn't exist. 3. Systematically replace `not grep` by the new function in `tests/scripts/components-*.sh` in all branches.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/mbedtls-framework#266
No description provided.