bats icon indicating copy to clipboard operation
bats copied to clipboard

GitHub for Windows compatibility

Open leahcim opened this issue 9 years ago • 1 comments

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:

  • [[ =~ ]]
  • <()
  • readlink
  • tput

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:

  • Bash 3.1.20(4)-release (i686-pc-msys) on Win 7/8.1 (GitHub for Windows)
  • Bash 3.2.57(1)-release (x86_64-apple-darwin14) on OS X Yosemite (10.10.5)
  • Bash 4.1.13(2)-release (sparc-sun-solaris2.11) on SunOS 5.11 (Solaris 11.1)
  • Bash 4.3.11(1)-release (x86_64-pc-linux-gnu) on Ubuntu 14.04.3 LTS
  • Bash 4.3.42(2)-release (i686-pc-msys) on Win 7/8.1 (Git for Windows)

Results

  • All tests are passing on Windows and Ubuntu.
  • On a Mac, in my tests sstephenson/bats/master (955309ab943ea157ded0c402df98b160bb45ff92) currently fails on 3 tests in test/bats.bats:
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
  • On SunOS 5.11 (Solaris 11.1), sstephenson/bats/master (955309ab943ea157ded0c402df98b160bb45ff92) currently fails on 10 tests in test/bats.bats.

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.

leahcim avatar Oct 24 '15 00:10 leahcim

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)

keradus avatar Dec 26 '17 19:12 keradus