Add initial version of test suite

This commit is contained in:
Michal Sojka 2024-12-22 21:58:19 +01:00
parent b2de70cc66
commit 70a0703a0e
3 changed files with 72 additions and 0 deletions

5
test/ros2nix Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)
export PYTHONPATH="$DIR:$PYTHONPATH"
exec python3 -m ros2nix "$@"

61
test/test.bats Normal file
View file

@ -0,0 +1,61 @@
# -*- bats-mode -*-
# shellcheck disable=SC2046
bats_require_minimum_version 1.5.0
bats_load_library bats-support
bats_load_library bats-assert
bats_load_library bats-file
setup_file() {
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
export DIR
# make executables in this directory visible to PATH
PATH="$DIR:$PATH"
}
setup() {
cd "$BATS_TEST_TMPDIR"
cp -a "$DIR/ws" .
}
@test "ros2nix --help" {
ros2nix --help
}
@test "fail on non-existent package.xml" {
run ! ros2nix ./non-existent.xml
}
@test "nixify local workspace" {
ros2nix $(find ws/src -name package.xml)
nix-build -A rosPackages.humble.ros-node -A rosPackages.jazzy.ros-node -A rosPackages.rolling.ros-node
}
@test "--output-as-nix-pkg-name" {
ros2nix --output-as-nix-pkg-name $(find ws/src -name package.xml)
assert [ -f ros-node.nix ]
assert [ -f library.nix ]
nix-build -A rosPackages.jazzy.ros-node
}
@test "--output-as-ros-pkg-name" {
ros2nix --output-as-ros-pkg-name $(find ws/src -name package.xml)
assert [ -f ros_node.nix ]
assert [ -f library.nix ]
nix-build -A rosPackages.jazzy.ros-node
}
@test "--flake" {
ros2nix --flake $(find ws/src -name package.xml)
nix flake check path:"${PWD}"
nix build path:"${PWD}#ros-node"
}
@test "--compare" {
ros2nix $(find ws/src -name package.xml)
ros2nix --compare $(find ws/src -name package.xml)
}