logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git

seq.sh (1002B)


  1. #!/bin/sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. seq="$(dirname "$0")/../cmd/seq"
  5. t ()
  6. {
  7. # $1 -> $test expression
  8. # $2 -> expected output
  9. count=$((count+1))
  10. out="$("$seq" -s, -- $1 2>&1)"
  11. ret="$?"
  12. if [ "$?" != 0 ]; then
  13. printf 'not ok %s - %s\n' "$count $1" "$out"
  14. elif [ "$out" != "$2" ]; then
  15. printf 'not ok %s - (%s != %s)\n' "$count $1" "$out" "$2"
  16. else
  17. printf 'ok %s\n' "$count $1"
  18. fi
  19. }
  20. count=0
  21. echo '1..20'
  22. # One arg
  23. t 1 '1'
  24. t 5 '1,2,3,4,5'
  25. t -1 '1,0,-1'
  26. t -5 '1,0,-1,-2,-3,-4,-5'
  27. # Two args
  28. t '0 1' '0,1'
  29. t '0 5' '0,1,2,3,4,5'
  30. t '10 15' '10,11,12,13,14,15'
  31. t '2 -2' '2,1,0,-1,-2'
  32. t '-2 2' '-2,-1,0,1,2'
  33. # Three args
  34. t '0 1 1' '0,1'
  35. t '0 1 5' '0,1,2,3,4,5'
  36. t '10 1 15' '10,11,12,13,14,15'
  37. t '0 2 5' '0,2,4'
  38. t '10 2 15' '10,12,14'
  39. t '0 1 -1' '0,-1'
  40. t '0 1 -5' '0,-1,-2,-3,-4,-5'
  41. t '-10 1 -15' '-10,-11,-12,-13,-14,-15'
  42. t '0 -1 -1' '0,-1'
  43. t '0 2 -5' '0,-2,-4'
  44. t '-10 2 -15' '-10,-12,-14'