mirror of
https://github.com/xcat2/xcat-core.git
synced 2026-09-10 19:46:24 +00:00
3e302e7f19
The go-xcat shell behavior tests were written as Perl harnesses, which made the shell assertions harder to read and kept shell-specific setup outside a native shell test framework. Add BATS to the GitHub Actions dependency set, run BATS tests from the same preserved source tree as the Perl unit suite, and move the go-xcat repository checks into xCAT-test/autotest/bats. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com>
133 lines
2.5 KiB
Bash
133 lines
2.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
repo_root()
|
|
{
|
|
printf '%s\n' "${BATS_TEST_DIRNAME}/../../.."
|
|
}
|
|
|
|
repo_path()
|
|
{
|
|
printf '%s/%s\n' "$(repo_root)" "$1"
|
|
}
|
|
|
|
require_repo_file()
|
|
{
|
|
local path
|
|
path="$(repo_path "$1")"
|
|
[ -r "$path" ] || skip "$path is required"
|
|
printf '%s\n' "$path"
|
|
}
|
|
|
|
read_file_or_empty()
|
|
{
|
|
local path="$1"
|
|
[ -f "$path" ] || return 0
|
|
cat "$path"
|
|
}
|
|
|
|
extract_shell_function()
|
|
{
|
|
local file="$1"
|
|
local name="$2"
|
|
|
|
awk -v name="$name" '
|
|
BEGIN {
|
|
signature = "^[[:space:]]*(function[[:space:]]+)?" name "([[:space:]]*\\(\\))?[[:space:]]*$"
|
|
inline_signature = "^[[:space:]]*(function[[:space:]]+)?" name "([[:space:]]*\\(\\))?[[:space:]]*\\{"
|
|
}
|
|
$0 ~ signature || $0 ~ inline_signature {
|
|
copy = 1
|
|
}
|
|
copy {
|
|
print
|
|
opened += gsub(/\{/, "{")
|
|
closed += gsub(/\}/, "}")
|
|
if (opened > 0 && opened == closed) {
|
|
found = 1
|
|
exit
|
|
}
|
|
}
|
|
END {
|
|
if (!found) {
|
|
exit 1
|
|
}
|
|
}
|
|
' "$file"
|
|
}
|
|
|
|
extract_shell_if_block()
|
|
{
|
|
local file="$1"
|
|
local start="$2"
|
|
|
|
awk -v start="$start" '
|
|
index($0, start) {
|
|
copy = 1
|
|
}
|
|
copy {
|
|
print
|
|
if ($0 ~ /^[[:space:]]*if[[:space:]\[]/) {
|
|
depth++
|
|
}
|
|
line = $0
|
|
while (line ~ /(^|[;[:space:]])fi([;[:space:]]|$)/) {
|
|
depth--
|
|
sub(/(^|[;[:space:]])fi([;[:space:]]|$)/, " ", line)
|
|
}
|
|
if (depth == 0) {
|
|
found = 1
|
|
exit
|
|
}
|
|
}
|
|
END {
|
|
if (!found) {
|
|
exit 1
|
|
}
|
|
}
|
|
' "$file"
|
|
}
|
|
|
|
extract_line_range()
|
|
{
|
|
local file="$1"
|
|
local start="$2"
|
|
local end="$3"
|
|
|
|
awk -v start="$start" -v end="$end" '
|
|
$0 ~ start {
|
|
copy = 1
|
|
}
|
|
copy {
|
|
print
|
|
if ($0 ~ end) {
|
|
found = 1
|
|
exit
|
|
}
|
|
}
|
|
END {
|
|
if (!found) {
|
|
exit 1
|
|
}
|
|
}
|
|
' "$file"
|
|
}
|
|
|
|
extract_first_matching_line()
|
|
{
|
|
local file="$1"
|
|
local pattern="$2"
|
|
|
|
awk -v pattern="$pattern" '
|
|
$0 ~ pattern {
|
|
print
|
|
found = 1
|
|
exit
|
|
}
|
|
END {
|
|
if (!found) {
|
|
exit 1
|
|
}
|
|
}
|
|
' "$file"
|
|
}
|