diff --git a/.gitignore b/.gitignore index 4d7f4fa653..ab5fc9d8a5 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,9 @@ tmp bin/configlet bin/configlet.exe .fake/ +.paket/paket.exe .vs/ tools/ build/ +packages/ TestResult.xml \ No newline at end of file diff --git a/.paket/paket.bootstrapper.exe b/.paket/paket.bootstrapper.exe new file mode 100644 index 0000000000..64fdf248bf Binary files /dev/null and b/.paket/paket.bootstrapper.exe differ diff --git a/.travis.yml b/.travis.yml index 7b3f8bb74a..379b999eb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: csharp script: - - bin/fetch-configlet - - bin/configlet . - - build.sh \ No newline at end of file + - ./bin/fetch-configlet + - ./bin/configlet . + - ./build.sh \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 7fc7af9c36..2fe5df9633 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,2 +1,4 @@ build_script: -- ps: .\build.ps1 \ No newline at end of file +- ps: .\build.cmd + +test: off \ No newline at end of file diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000000..29cd7d86c3 --- /dev/null +++ b/build.cmd @@ -0,0 +1,14 @@ +@echo off +cls + +.paket\paket.bootstrapper.exe +if errorlevel 1 ( + exit /b %errorlevel% +) + +.paket\paket.exe restore +if errorlevel 1 ( + exit /b %errorlevel% +) + +packages\FAKE\tools\FAKE.exe build.fsx %* \ No newline at end of file diff --git a/build.fsx b/build.fsx index 752b5f63b4..47d548a3b0 100644 --- a/build.fsx +++ b/build.fsx @@ -1,68 +1,61 @@ // Include Fake library -#r "tools/FAKE/tools/FakeLib.dll" +#r "./packages/FAKE/tools/FakeLib.dll" open Fake -open Fake.CscHelper open Fake.Testing.NUnit3 -// Properties -let sourceDir = "./exercises/" -let buildDir = getBuildParamOrDefault "buildDir" "./build/" -let buildExampleDir = buildDir @@ "example" -let buildTestDir = buildDir @@ "test" -let exampleDll = buildExampleDir @@ "example.dll" -let testDll = buildTestDir @@ "test.dll" -let nunitFrameworkDll = "tools/NUnit/lib/net45/nunit.framework.dll" +// Directories +let buildDir = "./build/" +let sourceDir = "./exercises/" -let exampleSourceFiles() = !! (buildExampleDir @@ "./**/*.cs") |> List.ofSeq -let testSourceFiles() = !! (buildTestDir @@ "./**/*.cs") |> List.ofSeq - -let compile output files = - files - |> Csc (fun p -> - { p with Output = output - References = [nunitFrameworkDll] - Target = Library }) +// Files +let solutionFile = buildDir @@ "/exercises.csproj" +let compiledOutput = buildDir @@ "xcsharp.dll" // Targets -Target "CleanExamples" (fun _ -> CleanDir buildExampleDir) -Target "CleanTests" (fun _ -> CleanDir buildTestDir) +Target "PrepareUnchanged" (fun _ -> + CleanDirs [buildDir] + CopyDir buildDir sourceDir allFiles +) -Target "CopyExamples" (fun _ -> CopyDir buildExampleDir sourceDir allFiles) -Target "CopyTests" (fun _ -> CopyDir buildTestDir sourceDir allFiles) +Target "BuildUnchanged" (fun _ -> + MSBuildRelease buildDir "Build" [solutionFile] + |> Log "Build unchanged output: " +) Target "PrepareTests" (fun _ -> - testSourceFiles() - |> ReplaceInFiles [("[Ignore(\"Remove to run test\")]", ""); (", Ignore = \"Remove to run test case\"", "")] + CleanDirs [buildDir] + CopyDir buildDir sourceDir allFiles + + let ignorePattern = "(\[Ignore\(\"Remove to run test\"\)]|, Ignore = \"Remove to run test case\")" + + !! (buildDir @@ "**/*Test.cs") + |> RegexReplaceInFilesWithEncoding ignorePattern "" System.Text.Encoding.UTF8 ) -Target "CompileExamples" (fun _ -> exampleSourceFiles() |> compile exampleDll) -Target "CompileTests" (fun _ -> testSourceFiles() |> compile testDll) +Target "BuildTests" (fun _ -> + MSBuildRelease buildDir "Build" [solutionFile] + |> Log "Build tests output: " +) Target "Test" (fun _ -> - Copy buildTestDir [nunitFrameworkDll] - - [testDll] - |> NUnit3 (fun p -> - { p with - ShadowCopy = false }) + if getEnvironmentVarAsBool "APPVEYOR" then + [compiledOutput] + |> NUnit3 (fun p -> { p with + ShadowCopy = false + ToolPath = @"C:\Tools\NUnit3\bin\nunit3-console.exe" + ResultSpecs = ["myresults.xml;format=AppVeyor"] }) + else + [compiledOutput] + |> NUnit3 (fun p -> { p with ShadowCopy = false }) ) -Target "Build" (fun _ -> ()) -Target "Default" (fun _ -> ()) - -"CleanExamples" - ==> "CopyExamples" - ==> "CompileExamples" - ==> "Build" +// Build order +"PrepareUnchanged" + ==> "BuildUnchanged" + ==> "PrepareTests" + ==> "BuildTests" + ==> "Test" -"CleanTests" - ==> "CopyTests" - ==> "PrepareTests" - ==> "CompileTests" - ==> "Test" - -"Build" ==> "Default" -"Test" ==> "Default" - -RunTargetOrDefault "Default" \ No newline at end of file +// start build +RunTargetOrDefault "Test" \ No newline at end of file diff --git a/build.ps1 b/build.ps1 deleted file mode 100644 index 6f17b6da10..0000000000 --- a/build.ps1 +++ /dev/null @@ -1,36 +0,0 @@ -$toolsDirectory = Join-Path $PSScriptRoot "tools" -$nugetDirectory = Join-Path $toolsDirectory "nuget" -$nugetExe = Join-Path $nugetDirectory "nuget.exe" -$fakeExe = Join-Path $toolsDirectory "fake/tools/fake.exe" -$nunitFrameworkDll = Join-Path $toolsDirectory "nunit/lib/net45/nunit.framework.dll" -$nunitConsoleExe = Join-Path $toolsDirectory "nunit.console/tools/nunit3-console.exe" - -If (!(Test-Path $nugetExe)) { - # Ensure the directory exists (which is required by DownloadFile) - New-Item $nugetDirectory -Type Directory | Out-Null - - $nugetUrl = "https://dist.nuget.org/win-x86-commandline/v3.3.0/nuget.exe" - (New-Object System.Net.WebClient).DownloadFile($nugetUrl, $nugetExe) -} - -If (!(Test-Path $nugetExe)) { - Throw "Could not find nuget.exe" -} - -& $nugetExe install FAKE -Version 4.17.1 -ExcludeVersion -OutputDirectory $toolsDirectory -If (!(Test-Path $fakeExe)) { - Throw "Could not find fake.exe" -} - -& $nugetExe install NUnit -Version 3.0.1 -ExcludeVersion -OutputDirectory $toolsDirectory -If (!(Test-Path $nunitFrameworkDll)) { - Throw "Could not find nunit.framework.dll" -} - -& $nugetExe install NUnit.Console -Version 3.0.1 -ExcludeVersion -OutputDirectory $toolsDirectory -If (!(Test-Path $nunitConsoleExe)) { - Throw "Could not find nunit3-console.exe" -} - -# Use FAKE to execute the build script -& $fakeExe $args \ No newline at end of file diff --git a/build.sh b/build.sh index 283d678645..374d5a0a0c 100755 --- a/build.sh +++ b/build.sh @@ -1,46 +1,33 @@ -#!/usr/bin/env bash +#!/bin/bash +if test "$OS" = "Windows_NT" +then + # use .Net -currentDirectory="$( cd "$( dirname "$0" )" && pwd )" -toolsDirectory=$currentDirectory/tools -nugetDirectory=$toolsDirectory/nuget -nugetExe=$nugetDirectory/nuget.exe -fakeExe=$toolsDirectory/FAKE/tools/FAKE.exe -nunitFrameworkDll=$toolsDirectory/NUnit/lib/net45/nunit.framework.dll -nunitConsoleExe=$toolsDirectory/NUnit.Console/tools/nunit3-console.exe + .paket/paket.bootstrapper.exe + exit_code=$? + if [ $exit_code -ne 0 ]; then + exit $exit_code + fi -if test ! -d $nugetDirectory; then - mkdir -p $nugetDirectory -fi + .paket/paket.exe restore + exit_code=$? + if [ $exit_code -ne 0 ]; then + exit $exit_code + fi -if test ! -f $nugetExe; then - nugetUrl="https://dist.nuget.org/win-x86-commandline/v3.3.0/nuget.exe" - wget -O $nugetExe $nugetUrl 2> /dev/null || curl -o $nugetExe --location $nugetUrl /dev/null - - if test ! -f $nugetExe; then - echo "Could not find nuget.exe" - exit 1 - fi - - chmod 755 $nugetExe -fi + packages/FAKE/tools/FAKE.exe $@ --fsiargs build.fsx +else + # use mono + mono .paket/paket.bootstrapper.exe + exit_code=$? + if [ $exit_code -ne 0 ]; then + exit $exit_code + fi -mono $nugetExe install FAKE -Version 4.17.1 -ExcludeVersion -OutputDirectory $toolsDirectory -if test ! -f $fakeExe; then - echo "Could not find fake.exe" - exit 1 -fi - -mono $nugetExe install NUnit -Version 3.0.1 -ExcludeVersion -OutputDirectory $toolsDirectory -if test ! -f $nunitFrameworkDll; then - echo "Could not find nunit.framework.dll" - exit 1 -fi - -mono $nugetExe install NUnit.Console -Version 3.0.1 -ExcludeVersion -OutputDirectory $toolsDirectory -if test ! -f $nunitConsoleExe; then - echo "Could not find nunit3-console.exe" - exit 1 -fi - -# Use FAKE to execute the build script -mono $fakeExe build.fsx $@ \ No newline at end of file + mono .paket/paket.exe restore + exit_code=$? + if [ $exit_code -ne 0 ]; then + exit $exit_code + fi + mono packages/FAKE/tools/FAKE.exe $@ --fsiargs -d:MONO build.fsx +fi \ No newline at end of file diff --git a/exercises/atbash-cipher/AtbashTest.cs b/exercises/atbash-cipher/AtbashTest.cs index f1dfcf442d..5f197fe2c5 100644 --- a/exercises/atbash-cipher/AtbashTest.cs +++ b/exercises/atbash-cipher/AtbashTest.cs @@ -3,7 +3,6 @@ [TestFixture] public class AtbashTest { - // change Ignore to false to run test case or just remove 'Ignore = true' [TestCase("no", ExpectedResult = "ml")] [TestCase("yes", ExpectedResult = "bvh", Ignore = "Remove to run test case")] [TestCase("OMG", ExpectedResult = "lnt", Ignore = "Remove to run test case")] diff --git a/exercises/beer-song/BeerTests.cs b/exercises/beer-song/BeerTest.cs similarity index 100% rename from exercises/beer-song/BeerTests.cs rename to exercises/beer-song/BeerTest.cs diff --git a/exercises/binary/BinaryTest.cs b/exercises/binary/BinaryTest.cs index a0f2285d8c..faf54e618a 100644 --- a/exercises/binary/BinaryTest.cs +++ b/exercises/binary/BinaryTest.cs @@ -3,7 +3,6 @@ [TestFixture] public class BinaryTest { - // change Ignore to false to run test case or just remove 'Ignore = true' [TestCase("1", ExpectedResult = 1)] [TestCase("10", ExpectedResult = 2, Ignore = "Remove to run test case")] [TestCase("11", ExpectedResult = 3, Ignore = "Remove to run test case")] diff --git a/exercises/difference-of-squares/DifferenceOfSquaresTests.cs b/exercises/difference-of-squares/DifferenceOfSquaresTest.cs similarity index 100% rename from exercises/difference-of-squares/DifferenceOfSquaresTests.cs rename to exercises/difference-of-squares/DifferenceOfSquaresTest.cs diff --git a/exercises/exercises.csproj b/exercises/exercises.csproj new file mode 100644 index 0000000000..cf39f91924 --- /dev/null +++ b/exercises/exercises.csproj @@ -0,0 +1,97 @@ + + + + + Debug + AnyCPU + {FEF69435-D885-45DD-A446-04FD3BD3F593} + Library + Properties + xcsharp + xcsharp + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + ..\packages\NUnit\lib\net20\NUnit.System.Linq.dll + True + True + + + ..\packages\NUnit\lib\net20\nunit.framework.dll + True + True + + + + + + + ..\packages\NUnit\lib\net35\nunit.framework.dll + True + True + + + + + + + ..\packages\NUnit\lib\net40\nunit.framework.dll + True + True + + + + + + + ..\packages\NUnit\lib\net45\nunit.framework.dll + True + True + + + + + + + ..\packages\NUnit\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll + True + True + + + + + \ No newline at end of file diff --git a/exercises/hexadecimal/HexadecimalTest.cs b/exercises/hexadecimal/HexadecimalTest.cs index f0974ac97a..71b3078900 100644 --- a/exercises/hexadecimal/HexadecimalTest.cs +++ b/exercises/hexadecimal/HexadecimalTest.cs @@ -3,7 +3,6 @@ [TestFixture] public class HexadecimalTest { - // change Ignore to false to run test case or just remove 'Ignore = true' [TestCase("1", ExpectedResult = 1)] [TestCase("c", ExpectedResult = 12, Ignore = "Remove to run test case")] [TestCase("10", ExpectedResult = 16, Ignore = "Remove to run test case")] diff --git a/exercises/octal/OctalTest.cs b/exercises/octal/OctalTest.cs index 1832219e54..a613c816c8 100644 --- a/exercises/octal/OctalTest.cs +++ b/exercises/octal/OctalTest.cs @@ -3,7 +3,6 @@ [TestFixture] public class OctalTest { - // change Ignore to false to run test case or just remove 'Ignore = true' [TestCase("1", ExpectedResult = 1)] [TestCase("10", ExpectedResult = 8, Ignore = "Remove to run test case")] [TestCase("17", ExpectedResult = 15, Ignore = "Remove to run test case")] diff --git a/exercises/paket.references b/exercises/paket.references new file mode 100644 index 0000000000..77bef3865c --- /dev/null +++ b/exercises/paket.references @@ -0,0 +1 @@ +NUnit \ No newline at end of file diff --git a/exercises/roman-numerals/RomanNumeralsTest.cs b/exercises/roman-numerals/RomanNumeralsTest.cs index add830fc14..69c24238d9 100644 --- a/exercises/roman-numerals/RomanNumeralsTest.cs +++ b/exercises/roman-numerals/RomanNumeralsTest.cs @@ -3,9 +3,6 @@ [TestFixture] public class RomanNumeralsTest { - // Change 'Ignore = true' to 'Ignore = false' to run a test case. - // You can also just remove 'Ignore = true'. - [TestCase(0, ExpectedResult = "")] [TestCase(1, ExpectedResult = "I", Ignore = "Remove to run test case")] [TestCase(2, ExpectedResult = "II", Ignore = "Remove to run test case")] diff --git a/exercises/saddle-points/SaddlePointTests.cs b/exercises/saddle-points/SaddlePointTest.cs similarity index 100% rename from exercises/saddle-points/SaddlePointTests.cs rename to exercises/saddle-points/SaddlePointTest.cs diff --git a/exercises/secret-handshake/SecretHandshakeTests.cs b/exercises/secret-handshake/SecretHandshakeTest.cs similarity index 100% rename from exercises/secret-handshake/SecretHandshakeTests.cs rename to exercises/secret-handshake/SecretHandshakeTest.cs diff --git a/exercises/tournament/TournamentTest.cs b/exercises/tournament/TournamentTest.cs index ca7b63adab..6daa4a92f6 100644 --- a/exercises/tournament/TournamentTest.cs +++ b/exercises/tournament/TournamentTest.cs @@ -6,59 +6,53 @@ [TestFixture] public class TournamentTest { - readonly string input1 = @" -Αllegoric Alaskians;Blithering Badgers;win -Devastating Donkeys;Courageous Californians;draw -Devastating Donkeys;Αllegoric Alaskians;win -Courageous Californians;Blithering Badgers;loss -Blithering Badgers;Devastating Donkeys;loss -Αllegoric Alaskians;Courageous Californians;win -".Trim(); + readonly string input1 = + "Αllegoric Alaskians;Blithering Badgers;win" + Environment.NewLine + + "Devastating Donkeys;Courageous Californians;draw" + Environment.NewLine + + "Devastating Donkeys;Αllegoric Alaskians;win" + Environment.NewLine + + "Courageous Californians;Blithering Badgers;loss" + Environment.NewLine + + "Blithering Badgers;Devastating Donkeys;loss" + Environment.NewLine + + "Αllegoric Alaskians;Courageous Californians;win".Trim(); - readonly string input2 = @" -Allegoric Alaskians;Blithering Badgers;win -Devastating Donkeys_Courageous Californians;draw -Devastating Donkeys;Allegoric Alaskians;win - -Courageous Californians;Blithering Badgers;loss -Bla;Bla;Bla -Blithering Badgers;Devastating Donkeys;loss -# Yackity yackity yack -Allegoric Alaskians;Courageous Californians;win -Devastating Donkeys;Courageous Californians;draw -Devastating Donkeys@Courageous Californians;draw -"; // Trim() omitted by design + private readonly string input2 = + "Allegoric Alaskians;Blithering Badgers;win" + Environment.NewLine + + "Devastating Donkeys_Courageous Californians;draw" + Environment.NewLine + + "Devastating Donkeys;Allegoric Alaskians;win" + Environment.NewLine + + "" + Environment.NewLine + + "Courageous Californians;Blithering Badgers;loss" + Environment.NewLine + + "Bla;Bla;Bla" + Environment.NewLine + + "Blithering Badgers;Devastating Donkeys;loss" + Environment.NewLine + + "# Yackity yackity yack" + Environment.NewLine + + "Allegoric Alaskians;Courageous Californians;win" + Environment.NewLine + + "Devastating Donkeys;Courageous Californians;draw" + Environment.NewLine + + "Devastating Donkeys@Courageous Californians;draw"; // Trim() omitted by design - readonly string input3 = @" -Allegoric Alaskians;Blithering Badgers;win -Devastating Donkeys;Allegoric Alaskians;win -Courageous Californians;Blithering Badgers;loss -Allegoric Alaskians;Courageous Californians;win -".Trim(); + private readonly string input3 = + "Allegoric Alaskians;Blithering Badgers;win" + Environment.NewLine + + "Devastating Donkeys;Allegoric Alaskians;win" + Environment.NewLine + + "Courageous Californians;Blithering Badgers;loss" + Environment.NewLine + + "Allegoric Alaskians;Courageous Californians;win".Trim(); - readonly string expected1 = @" -Team | MP | W | D | L | P -Devastating Donkeys | 3 | 2 | 1 | 0 | 7 -Αllegoric Alaskians | 3 | 2 | 0 | 1 | 6 -Blithering Badgers | 3 | 1 | 0 | 2 | 3 -Courageous Californians | 3 | 0 | 1 | 2 | 1 -".Trim(); + readonly string expected1 = + "Team | MP | W | D | L | P" + Environment.NewLine + + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7" + Environment.NewLine + + "Αllegoric Alaskians | 3 | 2 | 0 | 1 | 6" + Environment.NewLine + + "Blithering Badgers | 3 | 1 | 0 | 2 | 3" + Environment.NewLine + + "Courageous Californians | 3 | 0 | 1 | 2 | 1".Trim(); - readonly string expected2 = @" -Team | MP | W | D | L | P -Devastating Donkeys | 3 | 2 | 1 | 0 | 7 -Allegoric Alaskians | 3 | 2 | 0 | 1 | 6 -Blithering Badgers | 3 | 1 | 0 | 2 | 3 -Courageous Californians | 3 | 0 | 1 | 2 | 1 -".Trim(); + private readonly string expected2 = + "Team | MP | W | D | L | P" + Environment.NewLine + + "Devastating Donkeys | 3 | 2 | 1 | 0 | 7" + Environment.NewLine + + "Allegoric Alaskians | 3 | 2 | 0 | 1 | 6" + Environment.NewLine + + "Blithering Badgers | 3 | 1 | 0 | 2 | 3" + Environment.NewLine + + "Courageous Californians | 3 | 0 | 1 | 2 | 1".Trim(); - readonly string expected3 = @" -Team | MP | W | D | L | P -Allegoric Alaskians | 3 | 2 | 0 | 1 | 6 -Blithering Badgers | 2 | 1 | 0 | 1 | 3 -Devastating Donkeys | 1 | 1 | 0 | 0 | 3 -Courageous Californians | 2 | 0 | 0 | 2 | 0 -".Trim(); + private readonly string expected3 = + "Team | MP | W | D | L | P" + Environment.NewLine + + "Allegoric Alaskians | 3 | 2 | 0 | 1 | 6" + Environment.NewLine + + "Blithering Badgers | 2 | 1 | 0 | 1 | 3" + Environment.NewLine + + "Devastating Donkeys | 1 | 1 | 0 | 0 | 3" + Environment.NewLine + + "Courageous Californians | 2 | 0 | 0 | 2 | 0".Trim(); private string RunTally(string input) { diff --git a/exercises/trinary/TrinaryTest.cs b/exercises/trinary/TrinaryTest.cs index 8909dad0c9..c3e15004ea 100644 --- a/exercises/trinary/TrinaryTest.cs +++ b/exercises/trinary/TrinaryTest.cs @@ -3,7 +3,6 @@ [TestFixture] public class TrinaryTest { - // change Ignore to false to run test case or just remove 'Ignore = true' [TestCase("1", ExpectedResult = 1)] [TestCase("2", ExpectedResult = 2, Ignore = "Remove to run test case")] [TestCase("10", ExpectedResult = 3, Ignore = "Remove to run test case")] diff --git a/paket.dependencies b/paket.dependencies new file mode 100644 index 0000000000..94065bd2ce --- /dev/null +++ b/paket.dependencies @@ -0,0 +1,4 @@ +source https://www.nuget.org/api/v2/ +nuget FAKE +nuget NUnit +nuget NUnit.ConsoleRunner \ No newline at end of file diff --git a/paket.lock b/paket.lock new file mode 100644 index 0000000000..d0804d08d0 --- /dev/null +++ b/paket.lock @@ -0,0 +1,5 @@ +NUGET + remote: https://www.nuget.org/api/v2 + FAKE (4.37.2) + NUnit (3.4.1) + NUnit.ConsoleRunner (3.4.1)