# add\_test() assumes test executable is first string after COMMAND

**URL:** https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012
**Category:** Code
**Tags:** os:linux, tool:ctest
**Created:** [August 15, 2025, 5:03am UTC](https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012 "2025-08-15T05:03:20Z")
**Posts on this page:** 1
**Showing post:** 5

<div class="post-metadata">

### Author: ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)
#### Post date: [August 15, 2025, 7:29pm UTC](https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012/5 "2025-08-15T19:29:18Z")

</div>

Du you know [CMAKE\_CROSSCOMPILING\_EMULATOR](https://cmake.org/cmake/help/latest/variable/CMAKE_CROSSCOMPILING_EMULATOR.html)?

Let’s say you want to run your tests on a Raspberry Pi via SSH.

**File:** `run_remote.sh`

```bash
#!/usr/bin/env bash
set -e

TARGET_HOST="pi@192.168.1.42"
TARGET_DIR="/tmp/cmake_test"
REMOTE_BINARY="$TARGET_DIR/$(basename "$1")"

# 1. Copy binary to remote
ssh "$TARGET_HOST" "mkdir -p $TARGET_DIR"
scp "$1" "$TARGET_HOST:$REMOTE_BINARY"

# 2. Shift script args so remaining are test arguments
shift

# 3. Run binary on remote and forward stdout/stderr
ssh "$TARGET_HOST" "$REMOTE_BINARY" "$@"

```

Than you my use it like this:

```cmake
set(CMAKE_CROSSCOMPILING_EMULATOR
    ${CMAKE_SOURCE_DIR}/run_remote.sh
    CACHE STRING "Command to run executables on target")

add_executable(mytest test.cpp)
add_test(NAME mytest COMMAND mytest)

```

---

_[View the full topic](https://discourse.cmake.org/t/add-test-assumes-test-executable-is-first-string-after-command/15012)._
