generate-trycmd-test.sh 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/bash
  2. # Generate test data for the program
  3. if [ $# -ne 2 ]; then
  4. echo "Usage: $0 <test name> <test argument>"
  5. exit 1
  6. fi
  7. # Clean up previous test data
  8. if [ -f tests/cmd/"$1".toml ]; then
  9. rm tests/cmd/"$1".toml
  10. fi
  11. if [ -f tests/cmd/"$1".stdout ]; then
  12. rm tests/cmd/"$1".stdout
  13. fi
  14. if [ -f tests/cmd/"$1".stderr ]; then
  15. rm tests/cmd/"$1".stderr
  16. fi
  17. # Generate test data
  18. touch tests/cmd/"$1".toml
  19. echo 'bin.name = "eza"' >> tests/cmd/"$1".toml
  20. echo 'args = "'"$2"'"' >> tests/cmd/"$1".toml
  21. # Generate expected output
  22. if [ -f target/debug/eza ]; then
  23. target/debug/eza "$2" > tests/cmd/"$1".stdout 2> tests/cmd/"$1".stderr
  24. returncode=$?
  25. if [ $returncode -ne 0 ]; then
  26. echo -e 'status.code = '$returncode'' >> tests/cmd/"$1".toml
  27. exit 0
  28. fi
  29. else
  30. echo "Please build the program first"
  31. exit 1
  32. fi