Bläddra i källkod

Check on testlib exit that register-function has been actually called

mikemirzayanov 1 år sedan
förälder
incheckning
925cb4e212

+ 12 - 0
testlib.h

@@ -2292,6 +2292,8 @@ public:
 
 struct TestlibFinalizeGuard {
     static bool alive;
+    static bool registered;
+
     int quitCount, readEofCount;
 
     TestlibFinalizeGuard() : quitCount(0), readEofCount(0) {
@@ -2308,6 +2310,9 @@ struct TestlibFinalizeGuard {
 
             if (testlibMode == _validator && readEofCount == 0 && quitCount == 0)
                 __testlib_fail("Validator must end with readEof call.");
+
+            if (!registered)
+                __testlib_fail("Call register-function in the first line of the main (registerTestlibCmd or other similar)");
         }
 
         validator.writeTestOverviewLog();
@@ -2315,6 +2320,8 @@ struct TestlibFinalizeGuard {
 };
 
 bool TestlibFinalizeGuard::alive = true;
+bool TestlibFinalizeGuard::registered = false;
+
 TestlibFinalizeGuard testlibFinalizeGuard;
 
 /*
@@ -4073,6 +4080,7 @@ void registerGen(int argc, char *argv[], int randomGeneratorVersion) {
     random_t::version = randomGeneratorVersion;
 
     __testlib_ensuresPreconditions();
+    TestlibFinalizeGuard::registered = true;
 
     testlibMode = _generator;
     __testlib_set_binary(stdin);
@@ -4116,6 +4124,7 @@ void registerGen(int argc, char *argv[]) {
 
 void registerInteraction(int argc, char *argv[]) {
     __testlib_ensuresPreconditions();
+    TestlibFinalizeGuard::registered = true;
 
     testlibMode = _interactor;
     __testlib_set_binary(stdin);
@@ -4167,6 +4176,7 @@ void registerInteraction(int argc, char *argv[]) {
 
 void registerValidation() {
     __testlib_ensuresPreconditions();
+    TestlibFinalizeGuard::registered = true;
 
     testlibMode = _validator;
     __testlib_set_binary(stdin);
@@ -4178,6 +4188,7 @@ void registerValidation() {
 void registerValidation(int argc, char *argv[]) {
     registerValidation();
     validator.initialize();
+    TestlibFinalizeGuard::registered = true;
 
     for (int i = 1; i < argc; i++) {
         if (!strcmp("--testset", argv[i])) {
@@ -4253,6 +4264,7 @@ public:
 
 void registerTestlibCmd(int argc, char *argv[]) {
     __testlib_ensuresPreconditions();
+    TestlibFinalizeGuard::registered = true;
 
     testlibMode = _checker;
     __testlib_set_binary(stdin);

+ 1 - 0
tests/test-005_no-register/refs/r1/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-005_no-register/refs/r1/stderr

@@ -0,0 +1 @@
+FAIL Call register-function in the first line of the main (registerTestlibCmd or other similar)

+ 2 - 0
tests/test-005_no-register/refs/r1/stdout

@@ -0,0 +1,2 @@
+10
+3 7 10 1 9 5 4 8 6 2

+ 1 - 0
tests/test-005_no-register/refs/r2/exit_code

@@ -0,0 +1 @@
+3

+ 1 - 0
tests/test-005_no-register/refs/r2/stderr

@@ -0,0 +1 @@
+FAIL Call register-function in the first line of the main (registerTestlibCmd or other similar)

+ 2 - 0
tests/test-005_no-register/refs/r2/stdout

@@ -0,0 +1,2 @@
+10
+3 7 10 1 9 5 4 8 6 2

+ 7 - 0
tests/test-005_no-register/run.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+set -eo pipefail
+
+bash ../scripts/compile src/g.cpp
+bash ../scripts/test-ref r1 "$VALGRIND" ./g
+bash ../scripts/test-ref r2 "$VALGRIND" ./g 100
+rm -f g g.exe

+ 7 - 0
tests/test-005_no-register/src/g.cpp

@@ -0,0 +1,7 @@
+#include "testlib.h"
+
+int main(int argc, char* argv[]) {
+    int n = 10;
+    println(n);
+    println(rnd.perm(n, 1));
+}