#!/usr/bin/env execlineb
# SPDX-FileCopyrightText: Peter Pentchev <roam@ringlet.net>
# SPDX-License-Identifier: BSD-2-Clause

backtick -E tempd {
  mktemp -d -t utf8-locale-test.XXXXXX
}
trap {
  default {
    foreground {
      echo "Cleaning up ${tempd} in a ${SIGNAL} signal handler"
    }
    rm -rf -- $tempd
  }
}

foreground {
  if {
    pipeline {
      tar cf - --exclude .jj --exclude target .
    }
    cd $tempd
    tar xf -
  }
  
  cd ${tempd}
  
  if {
    uv sync --group testenv-unit-tests
  }
  if {
    rust/tools/el-build-and-test
  }
  if {
    if {
      cargo build --release
    }
    .venv/bin/python -- tests/functional.py -p target/release/u8loc
  }
  if {
    if {
      mkdir obj
    }
    cd obj
    if {
      cmake ..
    }
    if {
      make
    }
    cd ..
    .venv/bin/python -- tests/functional.py -p obj/c/u8loc/u8loc
  }
  if {
    if {
      uv venv venv-uvoxen
    }
    if {
      sh -c "set -e; . venv-uvoxen/bin/activate; uv pip install uvoxen"
    }
    venv-uvoxen/bin/uvoxen -p supported uv run
  }
  
  echo "Seems fine"
}

importas exitcode ?
foreground {
  echo "Cleaning up ${tempd}"
}
foreground {
  rm -rf -- $tempd
}
exit $exitcode
