TypedDevs / bashunit

A simple testing library for bash scripts. Test your bash scripts in the fastest and simplest way, discover the most modern bash testing library.
https://bashunit.typeddevs.com
MIT License
271 stars 21 forks source link

Use snapshots on acceptance tests #213

Closed antonio-gg-dev closed 8 months ago

antonio-gg-dev commented 8 months ago

I have refactored all the acceptance tests to use snapshots, and I have also taken the opportunity to categorize them and add extra tests.

During this process, I found some functionalities that are not working as expected, so I have taken the liberty of marking those tests as incomplete so that we can finish implementing/fixing/etc. them.

✅ To-do list

antonio-gg-dev commented 8 months ago

@khru @Chemaclass Can you validate if you like the new acceptance tests? If so, I'll refactor the rest

khru commented 8 months ago

@Tito-Kati this test fails on my machine.

✗ Failed: Install downloads the given version
    Expected 'bashunit - 0.8.0'
    but got ' _               _                   _
| |__   __ _ ___| |__  __ __ ____ (_) |_
| '_ \ / _' / __| '_ \| | | | '_ \| | __|
| |_) | (_| \__ \ | | | |_| | | | | | |_
|_.__/ \__,_|___/_| |_|\___/|_| |_|_|\__|
0.8.0'

And the test is todo

function test_install_downloads_the_given_version() {
  local install_dir="./lib/bashunit"
  local output

  output="$(./install.sh lib 0.8.0)"

  assert_equals\
    "$(printf "> Downloading a concrete version: '0.8.0'\n> bashunit has been installed in the 'lib' folder")"\
    "$output"
  assert_file_exists "$install_dir"
  todo "Fix next assertion fails when HEADER_ASCII_ART=true is set in your .env (overriding given --env option)"
  assert_equals\
    "$(printf "\e[1m\e[32mbashunit\e[0m - 0.8.0")"\
    "$("$install_dir" --env "$TEST_ENV_FILE" --version)"
}

Local solution but still a bug: change my .env config the test is using my .envconfig and not skipping even with a todo

image

How to reproduce it

Change on your local .env file

HEADER_ASCII_ART=true

Then you will see the error

antonio-gg-dev commented 8 months ago

@Tito-Kati this test fails on my machine.

✗ Failed: Install downloads the given version
    Expected 'bashunit - 0.8.0'
    but got ' _               _                   _
| |__   __ _ ___| |__  __ __ ____ (_) |_
| '_ \ / _' / __| '_ \| | | | '_ \| | __|
| |_) | (_| \__ \ | | | |_| | | | | | |_
|_.__/ \__,_|___/_| |_|\___/|_| |_|_|\__|
0.8.0'

And the test is todo

function test_install_downloads_the_given_version() {
  local install_dir="./lib/bashunit"
  local output

  output="$(./install.sh lib 0.8.0)"

  assert_equals\
    "$(printf "> Downloading a concrete version: '0.8.0'\n> bashunit has been installed in the 'lib' folder")"\
    "$output"
  assert_file_exists "$install_dir"
  todo "Fix next assertion fails when HEADER_ASCII_ART=true is set in your .env (overriding given --env option)"
  assert_equals\
    "$(printf "\e[1m\e[32mbashunit\e[0m - 0.8.0")"\
    "$("$install_dir" --env "$TEST_ENV_FILE" --version)"
}

Local solution but still a bug: change my .env config the test is using my .envconfig and not skipping even with a todo

image

How to reproduce it

Change on your local .env file

HEADER_ASCII_ART=true

Then you will see the error

I left the test running because if you don't have the ascii header it works fine, but I added the todo to remind us to fix it (todos don't stop the execution of the tests)