Repository: HandmadeMath/HandmadeMath (c)

Issue:
No way to run tests on Windows
Wondering if there's any interest in making project files (or some other build solution?) for running the test suite in MSVC.

I am happy to put them together if they'd be useful. I have VS 2015 and got those projects working there. Not sure if VS 2017 requires a separate solution version, but I could also make that project if it does.

I cannot get VS 2012 working without modifying the tests. C99 designated initializers weren't supported until VS 2013, it seems, and the tests use those. I could convert the tests to not use that feature (if the lib itself doesn't use it). I wanted to gauge interest in all this before starting that.


Discussion:
Hmm... I think solution files are unique per Visual Studio version (I think they even change with minor patches) and the version of build toolchain the user has on. This might be a case for cMake, just so people can generate "solution" files for any platform
I needed to use C99 designated initializers in order to make the tests run in both C and C++, so I doubt we'd be able to get rid of those. Although if you manage to find a way to make C register tests before the main function runs, by all means do so, because I struggled for quite a while to make that work.

Making the tests runnable within MSVC would be really good, though, considering how many of our users probably use MSVC. Our current test setup is built around Travis CI and gcc on my Macbook. CMake seems like a good option to investigate.
Renamed to reflect the main gist of the problem. I think it would be reasonable to support just the C++ tests on Windows, and it would be fine to do it through a batch file to keep the problem reasonably scoped. This will never run in CI anyway, unless Travis adds MSVC support, so we can just do what it takes to sanity-check work locally before committing it. 
@bvisness So apparently you can run our tests on Windows now with TravisCI 

Patch:
diff --git a/.travis.yml b/.travis.yml
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,19 @@
 language: cpp
+os:
+  - linux
+  - osx
 compiler:
   - clang
   - gcc
+matrix:
+  include:
+    # Windows x64 builds (MSVC)
+    - os: windows
+      script:
+        - ./test.bat travis
+
+before_install:
+  - eval "${MATRIX_EVAL}"
 install:
   - cd test
 script:


Test patch:
diff --git a/test/HandmadeTest.h b/test/HandmadeTest.h
--- a/test/HandmadeTest.h
+++ b/test/HandmadeTest.h
@@ -212,9 +212,9 @@ hmt_covercase* _hmt_covercases = 0;
 
 hmt_category _hmt_new_category(const char* name) {
     hmt_category cat = {
-        .name = name,
-        .num_tests = 0,
-        .tests = (hmt_test*) malloc(HMT_ARRAY_SIZE * sizeof(hmt_test))
+        name, // name
+        0, // num_tests
+        (hmt_test*) malloc(HMT_ARRAY_SIZE * sizeof(hmt_test)), // tests
     };
 
     return cat;
@@ -222,8 +222,8 @@ hmt_category _hmt_new_category(const char* name) {
 
 hmt_test _hmt_new_test(const char* name, hmt_test_func func) {
     hmt_test test = {
-        .name = name,
-        .func = func
+        name, // name
+        func, // func
     };
 
     return test;
@@ -231,10 +231,10 @@ hmt_test _hmt_new_test(const char* name, hmt_test_func func) {
 
 hmt_covercase _hmt_new_covercase(const char* name, int expected) {
     hmt_covercase covercase = {
-        .name = name,
-        .expected_asserts = expected,
-        .actual_asserts = 0,
-        .asserted_lines = (int*) malloc(HMT_ARRAY_SIZE * sizeof(int)),
+        name, // name
+        expected, // expected_asserts
+        0, // actual_asserts
+        (int*) malloc(HMT_ARRAY_SIZE * sizeof(int)), // asserted_lines
     };
 
     return covercase;
@@ -331,8 +331,8 @@ int hmt_run_all_tests() {
             printf("    %s:", test.name);
 
             hmt_testresult result = {
-                .count_cases = 0,
-                .count_failures = 0
+                0, // count_cases
+                0, // count_failures
             };
             test.func(&result);
 
diff --git a/test/hmm_test.h b/test/hmm_test.h
--- a/test/hmm_test.h
+++ b/test/hmm_test.h
@@ -3,6 +3,7 @@
 #define HANDMADE_TEST_IMPLEMENTATION
 #include "HandmadeTest.h"
 
+#undef COVERAGE // Make sure we don't double-define initializers from the header part
 #include "../HandmadeMath.h"
 
 #include "categories/ScalarMath.h"
diff --git a/test/test.bat b/test/test.bat
new file mode 100644
--- /dev/null
+++ b/test/test.bat
@@ -0,0 +1,27 @@
+@echo off
+
+if "%1%"=="travis" (
+    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=amd64
+) else (
+    where /q cl
+    if ERRORLEVEL 1 (
+        for /f "delims=" %%a in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -find VC\Auxiliary\Build\vcvarsall.bat') do (%%a x64)
+    )
+)
+
+if not exist "build" mkdir build
+pushd build
+
+cl /Fehmm_test_c.exe ..\HandmadeMath.c ..\hmm_test.c
+hmm_test_c
+
+cl /Fehmm_test_c_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.c ..\hmm_test.c
+hmm_test_c_no_sse
+
+cl /Fehmm_test_cpp.exe ..\HandmadeMath.cpp ..\hmm_test.cpp
+hmm_test_cpp
+
+cl /Fehmm_test_cpp_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.cpp ..\hmm_test.cpp
+hmm_test_cpp_no_sse
+
+popd