plasticrake / tplink-smarthome-api

TP-Link Smarthome WiFi API
MIT License
1.02k stars 141 forks source link

bats fails to run #127

Closed iva2k closed 3 years ago

iva2k commented 3 years ago

There are issues in bats:

npm run test:cli

output:

.../node_modules/bats/libexec/bats-core/bats: line 234: exec: bats-exec-suite: not found
.../node_modules/bats/libexec/bats-core/bats: line 234: bats-format-pretty: command not found

Trying to add '$BATS_ROOT/libexec/bats-core/' before each offending file resolves the errors, but there are few more such bare invocations across other files that fail the same. Adding the fix to each of them allows bats command to pass.

Environment:

Windows 10 bash for git: GNU bash, version 4.4.23(1)-release (x86_64-pc-msys)

I suspect that setting up PATH variable could fix it (add resolved $BATS_ROOT/libexec/bats-core/), but it is not the right fix.

iva2k commented 3 years ago

I figured out what is happening.

Using git bash on Windows 10, so it is bash WIndows issue.

I peeked into value of BATS_LIBEXEC set in bats script and added to PATH:

BATS_LIBEXEC="$(dirname "$(bats_readlinkf "${BASH_SOURCE[0]}")")"
export BATS_LIBEXEC
...
export PATH="$BATS_LIBEXEC;$PATH;."
...
# Added for debug of https://github.com/plasticrake/tplink-smarthome-api/issues/127
echo "BATS_LEBEXEC=$BATS_LIBEXEC"
BATS_LIBEXEC=C:/.../node_modules/bats/libexec/bats-core

When I run in bash:

export BATS_LIBEXEC=C:/.../node_modules/bats/libexec/bats-core
which bats-exec-suite

It gets an error:

which: no bats-exec-suite in (C:/.../node_modules/bats/libexec/bats-core:

Changing Windows-specific "C:/..." to bash-accepted form "/c/...":

export BATS_LIBEXEC=/c/.../node_modules/bats/libexec/bats-core
which bats-exec-suite

It gets no error:

/c/.../node_modules/bats/libexec/bats-core:

So in summary, bash on windows dirname returns "C:/...", but using it in PATH does not work, need to be "/c/...".

iva2k commented 3 years ago

The following fix makes bats run ok:

file node_modules/bats/libexec/bats-core/bats

- BATS_LIBEXEC="$(dirname "$(bats_readlinkf "${BASH_SOURCE[0]}")")"
+ BATS_LIBEXEC="$(cd "$(dirname "$(bats_readlinkf "${BASH_SOURCE[0]}")")"; pwd)"
iva2k commented 3 years ago

Posted issue and solution to https://github.com/bats-core/bats-core/issues/424

Closing here.