Browse Source

Improve AutoTest, fix off-by-one

* AutoTest now forward-declares test functions rather than having to
import the module. This is much simpler, plus made it possible to add
ProfilerAutoInstrument to the test set (automatically instrumenting
all tests)
* Fix off-by-one error in read-introspect-struct-s-expr. I'm not sure
why this didn't fail earlier
windows-imgui
Macoy Madson 3 months ago
parent
commit
e0b0fda84c
  1. 28
      src/AutoTest.cake
  2. 4
      src/Introspection.cake
  3. 7
      test/src/GameLibTests.cake

28
src/AutoTest.cake

@ -12,18 +12,14 @@
;; Post references resolved hook find-add-tests will create a main function and call test functions
(defun-comptime find-add-tests (environment (& EvaluatorEnvironment)
was-code-modified (& bool) &return bool)
was-code-modified (& bool) &return bool)
(var functions-to-test (<> std::vector (<> std::pair std::string (* (const Token)))))
(var required-imports (<> std::vector (<> std::pair (* (const char)) (* (const Token)))))
(for-in definition-pair (& ObjectDefinitionPair) (field environment definitions)
(unless (!= (in std string npos) (call-on find (field definition-pair first) "test--"))
(continue))
(call-on push_back functions-to-test (call (in std make_pair)
(field definition-pair first)
(field definition-pair second definitionInvocation)))
(call-on push_back required-imports (call (in std make_pair)
(path definition-pair . second . definitionInvocation > source)
(field definition-pair second definitionInvocation))))
(field definition-pair second definitionInvocation))))
(get-or-create-comptime-var total-tests-found int)
;; No more tests found this round. Exit, otherwise we'll get in an infinite modification loop
@ -34,12 +30,22 @@
;; We're copying this to the main def, so it's fine if it gets destroyed
(var test-body (<> std::vector Token))
(var main-definition (* (<> std::vector Token)) (new (<> std::vector Token)))
(call-on push_back (field environment comptimeTokens) main-definition)
(for-in function-pair (& (<> std::pair std::string (* (const Token)))) functions-to-test
(var function-name-token Token (deref (field function-pair second)))
(set (field function-name-token type) TokenType_Symbol)
(set (field function-name-token contents) (field function-pair first))
(var function-name-string-token Token function-name-token)
(set (field function-name-string-token type) TokenType_String)
;; Forward-declare test for the compiler. This helps us avoid having to import the test's
;; module into AutoTest
(tokenize-push (deref main-definition)
(declare-extern-function (token-splice-addr function-name-token) (&return int)))
(tokenize-push test-body
(fprintf stderr "\n------------- %s\n" (token-splice-addr
function-name-string-token))
@ -50,16 +56,6 @@
function-name-string-token))
(return 1))))
(var main-definition (* (<> std::vector Token)) (new (<> std::vector Token)))
(call-on push_back (field environment comptimeTokens) main-definition)
(for-in import-pair (& (<> std::pair (* (const char)) (* (const Token)))) required-imports
(var import-str Token (deref (field import-pair second)))
(set (field import-str type) TokenType_String)
(set (field import-str contents) (field import-pair first))
(tokenize-push (deref main-definition)
(import (token-splice-addr import-str))))
(tokenize-push (deref main-definition)
(defun main (&return int)
(var num-errors int 0)

4
src/Introspection.cake

@ -805,7 +805,7 @@
(offset-pointer-to-type struct-out value-offset (* (* (const char)))))
(var-cast-to copied-string (* char) (string-allocate (+ 1 value-length)))
(strncpy copied-string in-string value-length)
(set (at (+ 1 value-length) copied-string) 0)
(set (at value-length copied-string) 0)
(set (deref str-write) copied-string))
;; Nested introspectable structs
@ -1336,6 +1336,7 @@
;; (pointer overrides)
null))
(fprintf stderr "Struct A baseline:\n")
(write-introspect-struct-s-expr my-struct--metadata (addr a) stderr
write-introspect-struct-add-newline)
@ -1361,6 +1362,7 @@
(free (type-cast file-contents (* void)))
(fclose in-file))
(fprintf stderr "Read-in struct:\n")
(write-introspect-struct-s-expr my-struct--metadata (addr read-struct) stderr
write-introspect-struct-add-newline)

7
test/src/GameLibTests.cake

@ -67,12 +67,7 @@
"../src/AutoTest.cake" "../src/SDL.cake" "../src/Math.cake"
"../src/Aubio.cake" "../src/ImGui.cake" "../src/Dictionary.cake"
"../src/DynamicArray.cake" "../src/Introspection.cake" "../src/OpenGL.cake"
"../src/Tracy.cake"))
;; Because auto-instrumentation does not play nice with AutoTest
(gamelib-run-test "Profiler auto-instrument"
(array platform-config "../src/ProfilerAutoInstrument.cake"
"src/TestAutoInstrument.cake"))
"../src/Tracy.cake" "../src/ProfilerAutoInstrument.cake"))
(when test-ogre
(gamelib-run-test "Ogre" (array platform-config "src/OgreApp.cake"))

Loading…
Cancel
Save