kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

common.sh (1420B)


      1 #!/usr/bin/env bash
      2 
      3 t1_root() {
      4     cd "$(dirname "${BASH_SOURCE[0]}")/../../.." && pwd
      5 }
      6 
      7 t1_log_dir() {
      8     local root="$1"
      9     printf '%s\n' "$root/build/test/tier1/objlink/logs"
     10 }
     11 
     12 t1_work_dir() {
     13     local root="$1" name="$2"
     14     printf '%s\n' "$root/build/test/tier1/objlink/$name"
     15 }
     16 
     17 t1_require_exe() {
     18     local path="$1" hint="$2"
     19     if [ ! -x "$path" ]; then
     20         echo "missing executable: $path" >&2
     21         echo "$hint" >&2
     22         return 2
     23     fi
     24 }
     25 
     26 t1_clang_triple() {
     27     case "${1:-aa64}" in
     28         aa64|aarch64|arm64) printf 'aarch64-linux-gnu\n' ;;
     29         x64|x86_64|amd64) printf 'x86_64-linux-gnu\n' ;;
     30         rv64|riscv64) printf 'riscv64-linux-gnu\n' ;;
     31         *) echo "unsupported KIT_TEST_ARCH=$1" >&2; return 2 ;;
     32     esac
     33 }
     34 
     35 t1_run() {
     36     local log="$1"
     37     shift
     38     "$@" >"$log" 2>&1
     39 }
     40 
     41 t1_diff() {
     42     local expected="$1" actual="$2" diff_file="$3"
     43     diff -u "$expected" "$actual" >"$diff_file" 2>&1
     44 }
     45 
     46 t1_assert_grep() {
     47     local label="$1" pattern="$2" file="$3"
     48     if ! grep -Eq "$pattern" "$file"; then
     49         echo "$label: pattern not found: $pattern" >&2
     50         sed -n '1,160p' "$file" >&2 || true
     51         return 1
     52     fi
     53 }
     54 
     55 t1_assert_not_grep() {
     56     local label="$1" pattern="$2" file="$3"
     57     if grep -Eq "$pattern" "$file"; then
     58         echo "$label: unexpected pattern found: $pattern" >&2
     59         grep -En "$pattern" "$file" >&2 || true
     60         return 1
     61     fi
     62 }