From db69c4d443f6cc8d83f6d5c41feeb254882d9bf8 Mon Sep 17 00:00:00 2001 From: Jan Baier Date: Thu, 7 Mar 2024 11:12:09 +0100 Subject: [PATCH] Add script for finding out testapi usage Reference: https://progress.opensuse.org/issues/138032 --- os-autoinst-testapi-usage | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 os-autoinst-testapi-usage diff --git a/os-autoinst-testapi-usage b/os-autoinst-testapi-usage new file mode 100755 index 00000000..7ac13c08 --- /dev/null +++ b/os-autoinst-testapi-usage @@ -0,0 +1,39 @@ +#!/bin/bash -e + +get_function_list() { + grep -P '^sub \w+\s*[({:]' "$testapi_path" | cut -f2 -d' ' | grep -v ^_ | sort +} + +rgg() { + # needs ripgrep with pcre2 + rg --engine pcre2 --stats "(? /dev/null || { + echo "rg (ripgrep) not found, please install it first" >&2 + exit 2 +} + +if [ -f "$1" ]; then + testapi_path=$1 +else + testapi_path=$1/testapi.pm +fi +shift + +[ -r "$testapi_path" ] || { + echo "$testapi_path not found" >&2 + exit 1 +} +grep -q 'package testapi' "$testapi_path" || echo "Warning: provided file does not look like testapi.pm" >&2 + +while (($#)); do + get_function_list | while read -r; do + echo "$1 - ${REPLY} : $(rgg "${REPLY}" "$1" | tail -8 | head -n1)" + done + shift +done