Last active
          July 22, 2017 01:34 
        
      - 
      
- 
        Save jpluscplusm/0c164b95cc83de1f87b616360e7f375b to your computer and use it in GitHub Desktop. 
    Per-file setup/teardown support for BATS
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | setup() { | |
| # Global setup | |
| if [ $BATS_TEST_NUMBER -eq 1 ]; then | |
| { | |
| echo export FOO=bar | |
| } >${BATS_TMPDIR}/bats.import.$PPID | |
| fi | |
| . ${BATS_TMPDIR}/bats.import.$PPID | |
| # Per-test setup as per documentation | |
| } | |
| teardown() { | |
| # Global teardown | |
| if [ "$BATS_TEST_NAME" = "${BATS_TEST_NAMES[((${#BATS_TEST_NAMES[*]}-1))]}" ]; then | |
| rm -f ${BATS_TMPDIR}/bats.import.$PPID | |
| fi | |
| # Per-test teardown as per documentation | |
| } | |
| @test "foo" { | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment