Welcome to mirror list, hosted at ThFree Co, Russian Federation.

50-output-19-batslib_decorate.bats « test - github.com/bats-core/bats-support.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a4d4fcb63a1f33db8338b5c6bf9baef36d886359 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bats

load test_helper

@test 'batslib_decorate() <title>: encloses the input in a footer line and a header line containing <title>' {
  run bash -c "source '${TEST_MAIN_DIR}/load.bash'
               echo 'body' | batslib_decorate 'title'"
  [ "$status" -eq 0 ]
  [ "${#lines[@]}" -eq 3 ]
  [ "${lines[0]}" == '-- title --' ]
  [ "${lines[1]}" == 'body' ]
  [ "${lines[2]}" == '--' ]
}

@test 'batslib_decorate() works with modified path' {
  export PATH="$BATS_TEST_DIRNAME:$PATH"
  echo body | {
    # Verify stub
    run which cat
    [ "$status" -eq 0 ]
    [ "$output" = "$BATS_TEST_DIRNAME/cat" ]
    # Should still work
    run batslib_decorate 'title'
    [ "$status" -eq 0 ]
    [ "${#lines[@]}" -eq 3 ]
    [ "${lines[0]}" == '-- title --' ]
    [ "${lines[1]}" == 'body' ]
    [ "${lines[2]}" == '--' ]
  }
}

@test 'batslib_decorate() works with mock function' {
  echo body | {
    function cat {
      echo "Mocked cat"
    }
    [ "$(cat)" = "Mocked cat" ]
    # Should still work
    run batslib_decorate 'title'
    [ "$status" -eq 0 ]
    [ "${#lines[@]}" -eq 3 ]
    [ "${lines[0]}" == '-- title --' ]
    [ "${lines[1]}" == 'body' ]
    [ "${lines[2]}" == '--' ]
  }
}