From eb41dbc01f1e08777cea9d84fab51716af610381 Mon Sep 17 00:00:00 2001 From: larsbrubaker Date: Wed, 26 Feb 2014 11:05:58 -0800 Subject: [PATCH] Putting in new release tests to make sure all sorts of things are good when we deploy. Have a new command line argument of test that will run release tests. Put in two tests to ensure that we don't have DEBUG defined when we ship release builds. Wrote a exception dumper that will output data when we have an error. --- MatterControl.csproj | 2 ++ MatterControlApplication.cs | 13 +++++++++++- Testing/ReleaseTests.cs | 17 +++++++++++++++ Testing/TestingDispatch.cs | 42 +++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 Testing/ReleaseTests.cs create mode 100644 Testing/TestingDispatch.cs diff --git a/MatterControl.csproj b/MatterControl.csproj index 63fd2d869..5feec7499 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -98,6 +98,8 @@ + + diff --git a/MatterControlApplication.cs b/MatterControlApplication.cs index cd27b9f8e..c75aaecda 100644 --- a/MatterControlApplication.cs +++ b/MatterControlApplication.cs @@ -71,9 +71,20 @@ namespace MatterHackers.MatterControl public MatterControlApplication(double width, double height) : base(width, height) { - this.commandLineArgs = Environment.GetCommandLineArgs();; + this.commandLineArgs = Environment.GetCommandLineArgs(); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; + if (commandLineArgs.Length > 1 && commandLineArgs[1].ToUpper() == "TEST") + { + Testing.TestingDispatch testDispatch = new Testing.TestingDispatch(); + string[] testCommands = new string[commandLineArgs.Length-2]; + if (commandLineArgs.Length > 2) + { + commandLineArgs.CopyTo(testCommands, 2); + } + testDispatch.RunTests(testCommands); + } + //WriteTestGCodeFile(); if (File.Exists("RunUnitTests.txt")) { diff --git a/Testing/ReleaseTests.cs b/Testing/ReleaseTests.cs new file mode 100644 index 000000000..cb7a5e367 --- /dev/null +++ b/Testing/ReleaseTests.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace MatterHackers.MatterControl.Testing +{ + public static class ReleaseTests + { + public static void AssertDebugNotDefined() + { +#if DEBUG + throw new Exception("DEBUG is defined and should not be!"); +#endif + } + } +} diff --git a/Testing/TestingDispatch.cs b/Testing/TestingDispatch.cs new file mode 100644 index 000000000..87d499267 --- /dev/null +++ b/Testing/TestingDispatch.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.IO; +using System.Diagnostics; + +namespace MatterHackers.MatterControl.Testing +{ + public class TestingDispatch + { + string errorLogFileName = null; + public TestingDispatch() + { + errorLogFileName = string.Format("ErrorLog - {0:yyyy-MM-dd hh-mmtt}.txt", DateTime.Now); + string firstLine = string.Format("MatterControl Errors: {0:yyyy-MM-dd hh:mm:ss tt}", DateTime.Now); + using (StreamWriter file = new StreamWriter(errorLogFileName)) + { + file.WriteLine(errorLogFileName, firstLine); + } + } + + public void RunTests(string[] testCommands) + { + try { ReleaseTests.AssertDebugNotDefined(); } + catch (Exception e) { DumpException(e); } + + try { MatterHackers.GCodeVisualizer.GCodeFile.AssertDebugNotDefined(); } + catch (Exception e) { DumpException(e); } + } + + void DumpException(Exception e) + { + using (StreamWriter w = File.AppendText(errorLogFileName)) + { + w.WriteLine(e.Message); + w.Write(e.StackTrace); + w.WriteLine(); + } + } + } +}