The main method of the application should look as follows:

#include <igloo/igloo.h>
using namespace igloo;

int main(int argc, const *argv[])
{
  return TestRunner::RunAllTests(argc, argv);
}

This will automatically run all registered tests in the application.

Command line switches

If you pass argc and argv to TestRunner::RunAllTests() your test application supports the following command line switches:

--version                          Print version of Igloo and exit.
--help                             Print available command line switches.
--output=[default|vs|color|xunit]  Select output format.
    default: Igloo's default output format
    vs:      Visual Studio's output format
    color:   Colored output format
    xunit:   XUnit style output format

Line Numbers in Error Messages

To include line numbers in your error messages you can use the AssertThat() macro instead of Assert::That() construct.

Contexts

Igloo considers a test application to be an executable specification of the application that’s under test. The test application contains one or more contexts that each describe a state of the application under test and a set of specifications for what should hold true in that context.

#include <igloo/igloo.h>
using namespace igloo;

Context(ANewlyStartedGame)
{
  Spec(ShouldHaveAnEmptyBoard)
  {
    Assert::That(game.Positions(), Has().All().EqualTo(EmptyPosition));
  } 

  Game game;
};

Nested Contexts

Igloo enables you to create nested contexts. The inner context inherits and augments the properties of the outer context. This is a powerful feature that lets you organize your contexts in a way that enables you to create just the right amount of setup for each context.

#include <igloo/igloo.h>
using namespace igloo;

Context(ANewlyStartedGame)
{
  Spec(ShouldHaveAnEmptyBoard)
  {
    Assert::That(game.Positions(), Has().All().EqualTo(EmptyPosition));
  }

  Context(PlayerOneIsSelectedToStart)
  {
    void SetUp()
    {
      Parent().game.Select(PlayerOne);
    }

    Spec(ItShouldBePlayerOnesTurn)
    {
      Assert::That(Parent().game.NextPlayer(), Equals(PlayerOne));
    }
  };  

  Game game;
};

The Parent() operation is used to access the context directly outside the current context.