Skip to content

Commit e3a96b0

Browse files
committed
map sed syntax for freebsd instead of assuming we have gsed installed
1 parent 79c8d0a commit e3a96b0

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

tests/probes/sysctl/test_sysctl_probe_all.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function perform_test {
6060
# on the same line as the <unix-sys:name> element. Match the explicit name
6161
# tags so value payloads do not pollute the extracted key list.
6262
grep '<unix-sys:name>' "$result" | \
63-
xsed -E 's;.*<unix-sys:name>([^<]+)</unix-sys:name>.*;\1;g' | \
63+
sed -E 's;.*<unix-sys:name>([^<]+)</unix-sys:name>.*;\1;g' | \
6464
sort > "$ourNames"
6565

6666
echo "Diff (sysctlNames / ourNames): ------"

tests/test_common.sh.in

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,35 @@ make_temp_file() {
339339
xsed() {
340340
case $(uname) in
341341
FreeBSD)
342-
gsed "$@"
342+
if command -v gsed >/dev/null 2>&1; then
343+
gsed "$@"
344+
return
345+
fi
346+
347+
local inplace=0
348+
local arg
349+
local transformed=()
350+
351+
for arg in "$@"; do
352+
if [ "$arg" = "-i" ]; then
353+
inplace=1
354+
continue
355+
fi
356+
357+
# Translate the small subset of GNU sed escapes used by the test
358+
# suite so the fallback works with FreeBSD sed too.
359+
arg=${arg//\\s/[[:space:]]}
360+
arg=${arg//\\S/[^[:space:]]}
361+
arg=${arg//\\w/[[:alnum:]_]}
362+
arg=${arg//\\W/[^[:alnum:]_]}
363+
transformed+=("$arg")
364+
done
365+
366+
if [ $inplace -eq 1 ]; then
367+
sed -i '' "${transformed[@]}"
368+
else
369+
sed "${transformed[@]}"
370+
fi
343371
;;
344372
*)
345373
sed "$@"

0 commit comments

Comments
 (0)