bats icon indicating copy to clipboard operation
bats copied to clipboard

Support for command that return non-zero exit status

Open onknows opened this issue 6 years ago • 3 comments

I have a command that returns exit status 1. I want to test this but I noticed that Bats expects exit status to be zero. Else it stops executions. This is nice feature to add I think.

onknows avatar Jan 10 '18 14:01 onknows

Perhaps an override command could be added to ignore exit statuses?

tsikerdekis avatar Jan 10 '18 18:01 tsikerdekis

I'm only new to bats but I think this is already the case

root@1e8afabe18ae:~# cat false.bats 
#!/usr/bin/env bats

@test "non-zero exit - false" {
  run false
  [ ${status} -ne 0 ]
}

@test "non-zero exit - exit 5" {
  run exit 5
  [ ${status} -eq 5 ]
}
root@1e8afabe18ae:~# bats false.bats 
 ✓ non-zero exit - false
 ✓ non-zero exit - exit 5

2 tests, 0 failures
root@1e8afabe18ae:~# false; echo $?
1
root@1e8afabe18ae:~# bash -c 'exit 5'; echo $?
5

trnubo avatar Mar 22 '18 09:03 trnubo

This project is no longer being actively maintained by its original auther (see https://github.com/sstephenson/bats/issues/236).

You might want to migrate to the community maintained fork bats-core and report your issue there.

Potherca avatar Apr 25 '18 21:04 Potherca