Skip to content

MSVC build broken because run_test_params_arr[] is not initialized by a constant expression #795

@lmoellendorf

Description

@lmoellendorf

The commit Add support for randomizing test execution order in Unity breaks MSVC build because in build/test/test_dictionary_runner.c an array is not initialized by a constant expression:

  int number_of_tests = 6;
  struct UnityRunTestParameters run_test_params_arr[number_of_tests];

Though this code may be...

valid in C99 and in C11, if variable length array (VLA) is supported by
your implementation (VLAs are optional in C11). However, it seems Visual
studio doesn't seem to support VLAs and expects a "constant expression"
for array size as in C89.

(cited from Can't create array with constant size ("expected constant expression”))

Possible fix:

index cc82cfc..1a983f0 100755
@@ -502,7 +502,7 @@ class UnityTestRunnerGenerator
       end
     end
     output.puts
-    output.puts("  int number_of_tests = #{count_tests(tests)};")
+    output.puts("  #define number_of_tests #{count_tests(tests)}")
     output.puts('  struct UnityRunTestParameters run_test_params_arr[number_of_tests];')
     output.puts
     idx = 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions