#!/bin/sh -ex

cd ${AUTOPKGTEST_TMP:-/tmp}

arduino-cli config init

mkfifo stdin

arduino-language-server -log < stdin > stdout &
pid=$!

# Keep a file descriptor open to keep stdin pipe open.
exec 3>stdin

sleep 1

# Send initialize request.
tee stdin <<EOF
Content-Length: 164

{"jsonrpc":"2.0","method":"initialize","id":1,"params":{"processId":2,"capabilities":{},"rootUri":"file:///","clientInfo":{"version":"0.0.0","name":"smoke-test"}}}
EOF

sleep 1

kill $pid
wait

echo '' | cat stdout -

# Check the outputs.
grep -o '"name":"arduino-language-server"' stdout
grep 'arduino-cli found' inols-err.log
grep 'clangd found' inols-err.log
grep 'arduino-language-server Version' inols-err.log
