Question

I would like to automate git bisect (instructions also available at official Linux Kernel Git documenation for git bisect) for building a .NET project with MSBuild, and run unit tests for it with nunit-console.exe. However, these tools were built for use in a Windows development environment, and I'm having various issues with getting them to work in the Bash environment of msysgit, summarized as follows:

  1. Bash can't seem to find MSBuild.exe nor nunit-console.exe (path issue).
  2. Both MSBuild.exe and nunit-console.exe use Windows style commandline option flags, i.e. they begin with a foward slash, e.g. MSBuild.exe /M. In Bash the forward slashes cause errors, because a forward slash is what Unix/Linux/*nix systems use to represent directory paths.

This is the git bisect command I've been using:

$ git bisect start <bad commit> <good commit>
$ git bisect run auto-build-run-tests.sh

and these are the contents of auto-build-run-tests.sh:

#!/bin/sh
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

# Build solution.
echo "Building..."

MSBuild.exe \
    /consoleloggerparameters:ErrorsOnly \
    /maxcpucount \
    /nologo \
    /property:Configuration=Debug \
    /verbosity:quiet \
    "Epic-Project-of-Supreme-Awesome.sln"

# Check exit status.
# (status != 0) ?
status=$?
if [ $status -ne 0 ]
    then
        echo "Build failure, status $status."
        exit $status
fi

echo "Build success."

# Run unit tests
nunit-console.exe \
    /noresult \
    /stoponerror \
    "bin/Debug/ArtificialIntelligence.Tests.dll" \
    "bin/Debug/TravelingSalesManSolver.Tests.dll"

status=$?
if [ $status -ne 0 ]
    then
        echo "Test failure, status $status."
        exit $status
fi

echo "Tests passed."
Was it helpful?

Solution

To solve the path problem, I simply used an absolute path in the script. To solve the Windows-style forward-slash commandline-option problem, I escaped the forward-slash with another forward slash (I got that tip from another Stack Overflow answer, I'll link to it when I find it again).

So now the working script looks like this:

#!/bin/sh
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_03_02.html
# http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html

# Build solution.
echo "Building..."

c:/Windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe \
    //consoleloggerparameters:ErrorsOnly \
    //maxcpucount \
    //nologo \
    //property:Configuration=Debug \
    //verbosity:quiet \
    Epic-Project-of-Supreme-Awesome.sln

# Check exit status.
# (status != 0) ?
status=$?
if [ $status -ne 0 ]
    then
        echo "Build failure, status $status."
        exit $status
fi

echo "Build success."

# Run unit tests
nunit-console.exe \
    //noresult \
    //stoponerror \
    bin/Debug/ArtificialIntelligence.Tests.dll \
    bin/Debug/TravelingSalesManSolver.Tests.dll

status=$?
if [ $status -ne 0 ]
    then
        echo "Test failure, status $status."
        exit $status
fi

echo "Tests passed."

and once again, you run it like this:

$ git bisect start <bad commit> <good commit>
$ git bisect run auto-build-run-tests.sh
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top