<?xml version="1.0" encoding="utf-8" ?>
<project name="GallioTester" default="go">
  <!-- Project UppercuT - http://projectuppercut.org -->
  <!-- DO NOT EDIT THIS FILE - This follows a convention for testing with Integration tests being separated from Unit tests - find out more at http://uppercut.pbwiki.com -->
  <property name="build.config.settings" value="__NONE__" overwrite="false" />
  <include buildfile="${build.config.settings}" if="${file::exists(build.config.settings)}" />
  <property name="path.separator" value="${string::trim(path::combine(' ', ' '))}" />
  <include buildfile="..${path.separator}csharp.functions" />
  <property name="file.current.no_extension" value="gallio.test" />
  <property name="dirs.current" value="${directory::get-parent-directory(project::get-buildfile-path())}" />
  <property name="path.to.toplevel" value="..${path.separator}.." />
  <property name="folder.build_scripts" value="build" overwrite="false" />
  <property name="folder.build_scripts_custom" value="build.custom" overwrite="false" />
  <property name="dirs.build_scripts_custom" value="${dirs.current}${path.separator}${path.to.toplevel}${path.separator}${folder.build_scripts_custom}${path.separator}analyzers" />
  <property name="folder.code_build" value="build_output" overwrite="false" />
  <property name="dirs.build" value="${dirs.current}${path.separator}${path.to.toplevel}${path.separator}${folder.code_build}" />
  <property name="folder.app.drop" value="${project.name}" overwrite="false" />
  <property name="dirs.build.code" value="${dirs.build}${path.separator}${folder.app.drop}" overwrite="false" />
  <property name="folder.build_artifacts" value="build_artifacts" overwrite="false" />
  <property name="dirs.build_artifacts" value="${path::get-full-path(dirs.build)}${path.separator}${folder.build_artifacts}" />
  <property name="dirs.test_results" value="${dirs.build_artifacts}${path.separator}gallio" overwrite="false" />
  <property name="file.test_results" value="gallio-results" overwrite="false" />
  <property name="time.limit.in.seconds" value="240" />
  
  <property name="file.custom.step.before" value="${dirs.build_scripts_custom}${path.separator}${file.current.no_extension}.pre.step" />
  <property name="file.custom.step.after" value="${dirs.build_scripts_custom}${path.separator}${file.current.no_extension}.post.step" />
  <property name="file.custom.step.replace" value="${dirs.build_scripts_custom}${path.separator}${file.current.no_extension}.replace.step" />
  <property name="is.replaced" value="false" />
  <property name="fail.build.on.error" value="true" />

  <target name="go" depends="run_tasks" />

  <target name="run_tasks">
    <echo message="Running ${project::get-name()} tasks." />
    <call target="prepare" if="${target::exists('prepare')}" />
    <call target="custom_tasks_before" if="${target::exists('custom_tasks_before')}"  />
    <call target="custom_tasks_replace" if="${target::exists('custom_tasks_replace')}"  />
    <call target="run_normal_tasks" if="${not is.replaced}" />
    <call target="custom_tasks_after" if="${target::exists('custom_tasks_after')}" />
  </target>

  <target name="run_normal_tasks"
          depends="run_tests"
          description="Testing with Gallio." />

  <target name="custom_tasks_before">
    <echo message="Running custom tasks if ${file.custom.step.before} exists." />
    <nant buildfile="${file.custom.step.before}" inheritall="true" if="${file::exists(file.custom.step.before)}" failonerror="${fail.build.on.error}" />
    <exec program="powershell.exe" if="${file::exists(file.custom.step.before + '.ps1')}" failonerror="${fail.build.on.error}">
      <arg value="${path::get-full-path(file.custom.step.before + '.ps1')}" />
    </exec>
    <exec program="ruby.exe" if="${file::exists(file.custom.step.before + '.rb')}" failonerror="${fail.build.on.error}">
      <arg value="${path::get-full-path(file.custom.step.before + '.rb')}" />
    </exec>
  </target>

  <target name="custom_tasks_replace">
    <echo message="Running custom tasks instead of normal tasks if ${file.custom.step.replace} exists." />
    <property name="is.replaced" value="true" if="${file::exists(file.custom.step.replace)}" />
    <nant buildfile="${file.custom.step.replace}" inheritall="true" if="${file::exists(file.custom.step.replace)}" failonerror="${fail.build.on.error}" />
    <property name="is.replaced" value="true" if="${file::exists(file.custom.step.replace + '.ps1')}" />
    <exec program="powershell.exe" if="${file::exists(file.custom.step.replace + '.ps1')}" failonerror="${fail.build.on.error}" >
      <arg value="${path::get-full-path(file.custom.step.replace + '.ps1')}" />
    </exec>
    <property name="is.replaced" value="true" if="${file::exists(file.custom.step.replace + '.rb')}" />
    <exec program="ruby.exe" if="${file::exists(file.custom.step.replace + '.rb')}" failonerror="${fail.build.on.error}" >
      <arg value="${path::get-full-path(file.custom.step.replace + '.rb')}" />
    </exec>
  </target>

  <target name="prepare">
    <echo message="Removing and adding ${dirs.test_results}."/>
    <delete dir="${dirs.test_results}" failonerror="false" />
    <mkdir dir="${dirs.test_results}" />
  </target>

  <target name="load_tasks">
    <echo message="Loading Gallio Nant Tasks from Program Files." />
    <loadtasks assembly="C:${path.separator}Program Files (x86)${path.separator}Gallio${path.separator}bin${path.separator}Gallio.NAntTasks.dll" if="${file::exists('C:' + path.separator + 'Program Files (x86)' + path.separator + 'Gallio' + path.separator + 'bin' + path.separator + 'Gallio.NAntTasks.dll')}" />
    <loadtasks assembly="C:${path.separator}Program Files${path.separator}Gallio${path.separator}bin${path.separator}Gallio.NAntTasks.dll" if="${file::exists('C:' + path.separator + 'Program Files' + path.separator + 'Gallio' + path.separator + 'bin' + path.separator + 'Gallio.NAntTasks.dll')}" />
  </target>

  <target name="run_tests" depends="prepare,load_tasks" description="Running Unit Tests">
    <echo message="Running tests using Gallio and putting results in ${dirs.test_results}."/>
    <gallio working-directory="${dirs.build}"
            report-types="Html;Xml;Text"
            report-directory="${dirs.test_results}"
            report-name-format="${file.test_results}"
            show-reports="false"
            failonerror="true"
            verbosity="Normal"
            echo-results="true"
            run-time-limit="${time.limit.in.seconds}"
            filter="exclude Category:Database or Category:Integration or Category:Slow or Category:NotWorking or Categroy:Ignore or Category:database or Category:integration or Category:slow or Category:notworking or Categroy:ignore"
            >
      <files>
        <exclude name="${dirs.build.code}${path.separator}lib${path.separator}**" />
        <exclude name="${dirs.build.code}${path.separator}**${path.separator}*Database*dll" />
        <exclude name="${dirs.build.code}${path.separator}**${path.separator}*.Integration*dll" />
        <exclude name="${dirs.build.code}${path.separator}**${path.separator}TestFu.dll" />
        <include name="${dirs.build.code}${path.separator}**${path.separator}*Test*dll" />
        <include name="${dirs.build.code}${path.separator}**${path.separator}*.Spec*dll" />
      </files>
    </gallio>
  </target>

  <target name="run_all_tests" depends="prepare,load_tasks" description="Running All Unit Tests">
    <echo message="Running all tests (including integration tests) using Gallio and putting results in ${dirs.test_results}."/>
    <gallio working-directory="${dirs.build}"
            report-types="Html;Xml;Text"
            report-directory="${dirs.test_results}"
            report-name-format="${file.test_results}"
            show-reports="false"
            failonerror="true"
            verbosity="Normal"
            echo-results="true"
            run-time-limit="${time.limit.in.seconds}"
            >
      <files>
        <exclude name="${dirs.build.code}${path.separator}lib${path.separator}**" />
        <exclude name="${dirs.build.code}${path.separator}**${path.separator}TestFu.dll" />
        <include name="${dirs.build.code}${path.separator}**${path.separator}*Test*dll" />
        <include name="${dirs.build.code}${path.separator}**${path.separator}*.Spec*dll" />
      </files>
    </gallio>
  </target>

  <target name="open_results">
    <echo message="Opening results - ${path::get-full-path(dirs.test_results) + path.separator + file.test_results + '.html'}" />
    <results display="${path::get-full-path(dirs.test_results) + path.separator + file.test_results + '.html'}" />
  </target>

  <target name="custom_tasks_after">
    <echo message="Running custom tasks if ${file.custom.step.after} exists." />
    <nant buildfile="${file.custom.step.after}" inheritall="true" if="${file::exists(file.custom.step.after)}" failonerror="${fail.build.on.error}" />
    <exec program="powershell.exe" if="${file::exists(file.custom.step.after + '.ps1')}" failonerror="${fail.build.on.error}" >
      <arg value="${path::get-full-path(file.custom.step.after + '.ps1')}" />
    </exec>
    <exec program="ruby.exe" if="${file::exists(file.custom.step.after + '.rb')}" failonerror="${fail.build.on.error}" >
      <arg value="${path::get-full-path(file.custom.step.after + '.rb')}" />
    </exec>
  </target>

</project>