Installing pgTap in windows with msys2 and mingw64

This weekend we spent sometime moving PostGIS/pgRouting windows buildbot Winnie to new hardware. Leo did the hardware and I handled installing and reconfiguring stuff. While I was at it, I upgraded to new Jenkins. Vicky Vergara has been bugging me to setup pgTap so she can run her pgRouting pgTap tests to make sure they work on windows. She's got 22488 tests. She just loves pgTap. Last time I tried installing pgTap I gave up, but I was in mood for experimentation so gave it another chance.

Main obstacle was installing pg_prove perl module which is commonly used with pgTap. I couldn't get this to install under msys cause it gave some sort of out of memory error and I hadn't migrated winnie to msys2 yet. For those unfamiliar msys is a 32-bit chain that gives you a Unix like toolbelt under windows. Msys2 is a much nicer new project that does what Msys did, but with a nice package manager called pacman and that has a 32-bit and 64-bit variant. To get the almost full unix experience under windows, you would couple this with mingw-w64 which is a much nicer set of gnu-compiles than the old mingw. I should add, getting a functioning unix shell and compilers, is much less painful than installing Visual Studio. Most everything is extract and go and copiable. so when I get a new workstation, I just copy over my folders, or copy stuff to Winnie.

For those interested in running with msys2. There is an msys2 for 64-bit and msys2 for 32-bit where as the regular old msys was just a 32-bit. I use 2 chains for building all my PostgreSQL extensions. msys2 (32-bit)/mingw-w64 32-bit chain and msys2 (64-bit)/mingw-w64 64-bit chain. Though it's not required, I like to have my 32-bits with my 32-bits and 64-bits with my 64-bit and keep them separate just in case I ever need to run on a 32-bit windows box.

Download a mingw-64 from https://mingw-w64.org. Extract somewhere and change msys2/ets/fstab to have lines something like:

# For a description of the file format, see the Users Guide
# http://cygwin.com/cygwin-ug-net/using.html#mount-table

# DO NOT REMOVE NEXT LINE. It remove cygdrive prefix from path
none / cygdrive binary,posix=0,noacl,user 0 0
c:/projects /projects
c:/projects/sources /sources
c:/ming64gcc48/mingw64 /mingw
c:/ming64gcc48/mingw64 /mingw64
#I use 32-bit cmake for building pgRouting. 
#Get from https://cmake.org/download/ since it has msys/mingw generator scripts
#one that you get from pacman does not.
C:/projects/cmake-3.7.2-win32-x86 /cmake

Launch msys batch script:

pacman -Syu
pacman --needed -S git
pacman --needed -S autoconf automake libtool make patch dos2unix
pacman --needed -S wget unzip bison

Now msys2 comes packaged with perl already, so to install pg_prove, you run this from the msys2 console.

cpan TAP::Parser::SourceHandler::pgTAP

To install pgTap, you just do the usual, like any other Unix/Linux user, after you have compiled PostgreSQL using msys2/mingw64.

export PGPATH=/projects/postgresql/rel/pg96w64gcc48
export PATH="${PGPATH}/bin:${PGPATH}/lib:${PATH}" 
export USE_PGXS=1

cd /projects/postgresql/extensions
rm -rf pgtap
git clone https://github.com/theory/pgtap.git pgtap
cd pgtap
git pull
make
make install

Then install in your db you will use for testing:

CREATE EXTENSION pgtap;

Note that pgTap extensions you build, can be copied over to a VC++ PostgreSQL compiled (no binaries for it, so just copy the pgtap* files from share/extension) and you can run against a PostgreSQL VC++ build even under msys2.

Vicky has tons of pgTap tests here launched with pg_prove_tests.sh.