Files
drharness/tests/test_prompt_file.sh
T
hal9000 48a3f15999 Add -P flag to read prompt from file
Implement issue 185: Create a new flag -P that reads the prompt from a
file instead of the command line.

Changes:
- Add -P flag parsing in main.cpp
- Read prompt content from specified file
- Update help message
- Update README.md documentation
- Add test_prompt_file.sh with tests for basic, multi-line, and error cases
2026-07-22 14:04:04 +00:00

49 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# test_prompt_file.sh - Validates the -P flag reads prompt from file
# Test 1: Basic prompt file reading
echo "This is my prompt from a file" > prompt.txt
be_done 'Response received' | "${DRHARNESS}" -F chat.json -n -P prompt.txt -d
# Verify the prompt from the file was stored in the chat history
STORED_PROMPT=$(dr_result chat.json 0)
if [ "${STORED_PROMPT}" != "This is my prompt from a file" ]; then
echo "FAIL: prompt_file - prompt not read correctly"
echo "Expected: 'This is my prompt from a file'"
echo "Got: '${STORED_PROMPT}'"
exit 1
fi
# Test 2: Multi-line prompt file
cat > multiline_prompt.txt << 'PROMPT'
Line 1
Line 2
Line 3
PROMPT
be_done 'Multi-line response' | "${DRHARNESS}" -F chat2.json -n -P multiline_prompt.txt -d
# Verify multi-line prompt was stored correctly
STORED_PROMPT=$(dr_result chat2.json 0)
EXPECTED_MULTILINE="Line 1
Line 2
Line 3"
if [ "${STORED_PROMPT}" != "${EXPECTED_MULTILINE}" ]; then
echo "FAIL: prompt_file multiline - prompt not read correctly"
echo "Expected:"
echo "${EXPECTED_MULTILINE}"
echo "Got:"
echo "${STORED_PROMPT}"
exit 1
fi
# Test 3: Non-existent file should fail
if "${DRHARNESS}" -F chat3.json -n -P nonexistent.txt -d < /dev/null 2>stderr_output; then
echo "FAIL: prompt_file nonexistent - should have failed"
cat stderr_output
exit 1
fi
echo "PASS: prompt_file"