sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 519 forks source link

GitHub for Windows compatibility #128

Open leahcim opened 8 years ago

leahcim commented 8 years ago

Hi, I wonder if this is something you'd consider for the master branch.

Background

I was checking if I could use Bats as a testing framework for my completion script (https://github.com/LeahCim/yo-completion/blob/master/yo.bash), which is supposed to be cross-compatible. Sadly, I discovered that Bats won't install on Windows at all if ran from "Git Shell" bundled with GitHub for Windows. Instead, it starts an infinite loop trying to resolve a link while readlink is not available.

Problem

Currently, GitHub for Windows comes with an old version of msysGit with Bash 3.1 without native regex support (not compiled into this msysGit Bash version). Additionally, not all Coreutils are available. In effect this comes down to the missing support for:

On top of that, the default terminal on Windows, Windows Console, only has a few ready-to-use fonts, which display empty boxes for the current tick (✓) and cross (✗) symbols used by bats in terminal. While adding more fonts to the Console is possible, it's a bit of a hassle: http://superuser.com/a/5079

Solution

This PR addresses all the above by replacing the offending constructs by their equivalents (e.g. [[ $VAR = <glob/extglob> ]] instead of [[ $VAR =~ <regex> ]] ), or working around the limitations:

I took the liberty to assume 80 columns in case tput is missing or if $TERM equals "msys". This makes sense on Windows, where 80 is the default and the maximum for the Console. It also seems to degrade gracefully when console is made narrower.

Additionally, when $TERM equals "msys", alternative tick (√) and cross (×) are used.

Tests

The updated code was tested against:

not ok 11 one failing test
# (in test file test/bats.bats, line 72)
#   `[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]' failed

not ok 13 failing test with significant status
# (in test file test/bats.bats, line 89)
#   `[ "${lines[3]}" = "#   \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]' fail

not ok 22 failing test file outside of BATS_CWD
# (in test file test/bats.bats, line 156)
#   `[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]' failed

This PR doesn't change that. The 3 tests still fail on a Mac and 10 same tests fail on SunOS Solaris, everything else passes, including the new test for ticks and crosses.

keradus commented 6 years ago

looks like really great work here, yet not sure what is the status here. already extra old, any chances to have bats working on Windows ? (probably would be nice to integrate AppVeyor to repo itself)