Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

output.bats 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/usr/bin/env bats
  2. @test "task1: Check that we have a debug output" {
  3. run stat "$BATS_TEST_DIRNAME/../target/debug/task1"
  4. [ "$status" -eq 0 ]
  5. }
  6. # Check lines of output
  7. # wc output with white spaces is trimmed by xargs
  8. @test "task1: Output with to no paras must be exact 1 line long" {
  9. run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task1' 1 | wc -l | xargs"
  10. [ "$output" = "1" ]
  11. }
  12. # wc output with white spaces is trimmed by xargs
  13. @test "task1: Output with one para must be exact 1 line long" {
  14. run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task1' -1 | wc -l | xargs"
  15. [ "$output" = "1" ]
  16. }
  17. # wc output with white spaces is trimmed by xargs
  18. @test "task1: Output with correct para must be exact 3 line long" {
  19. run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task1' 2 3 4 5 6 7 8 9 | wc -l | xargs"
  20. [ "$output" = "3" ]
  21. }
  22. # Check results
  23. @test "task1: 1 -2 3 -4 5" {
  24. run "$BATS_TEST_DIRNAME/../target/debug/task1" 1 -2 3 -4 5
  25. [[ "${lines[0]}" =~ "sending to childs: 1 -2 3 -4 5" ]]
  26. [[ "${lines[1]}" =~ "Sum = 3" ]]
  27. [[ "${lines[2]}" =~ "Mul = 120" ]]
  28. }
  29. @test "task1: 1 -2 3 -4 5 100 -400 5332 3290 -22 -4646 -1 -1" {
  30. run "$BATS_TEST_DIRNAME/../target/debug/task1" 1 -2 3 -4 5 100 -400 5332 3290 -22 -4646 -1 -1
  31. [[ "${lines[0]}" =~ "sending to childs: 1 -2 3 -4 5 100 -400 5332 3290 -22 -4646 -1 -1" ]]
  32. [[ "${lines[1]}" =~ "Sum = 3655" ]]
  33. [[ "${lines[2]}" =~ "Mul = -8606551312128000000" ]]
  34. }
  35. @test "task1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" {
  36. run "$BATS_TEST_DIRNAME/../target/debug/task1" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
  37. [[ "${lines[0]}" =~ "sending to childs: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20" ]]
  38. [[ "${lines[1]}" =~ "Sum = 210" ]]
  39. [[ "${lines[2]}" =~ "Mul = 2432902008176640000" ]]
  40. }
  41. # Status checks
  42. @test "task1: Output with wrong args (1) does not crash" {
  43. run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task1' a b c "
  44. [ "$status" = 1 ]
  45. }
  46. # Status checks
  47. @test "task1: Output with wrong args (2) does not crash" {
  48. run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task1' 1 - 2 "
  49. [ "$status" = 1 ]
  50. }
  51. @test "task1: Overflow Output does not crash" {
  52. run bash -c "'$BATS_TEST_DIRNAME/../target/debug/task1' 10000 10000 10000 10000 10000"
  53. [ "$status" = 1 ]
  54. }