summaryrefslogtreecommitdiff
path: root/src/unittest.cc
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2021-09-14 07:46:43 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2021-09-14 07:46:43 +0200
commitba04d2889a4e017c6043bac9951f722e60b63bc5 (patch)
tree1267f9264dfe81aadeac46446ee6122a5abe5190 /src/unittest.cc
parentf7fda8ca8841552b54ce72ed8ca9156cc09368d0 (diff)
Add suport for building and running unittests with the 'check' target.
Diffstat (limited to 'src/unittest.cc')
-rw-r--r--src/unittest.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/unittest.cc b/src/unittest.cc
new file mode 100644
index 0000000..d2d5167
--- /dev/null
+++ b/src/unittest.cc
@@ -0,0 +1,34 @@
+#include "unittest.h"
+
+#include <iostream>
+
+#include "execute.h"
+#include "settings.h"
+#include "task.h"
+
+int runUnitTests(std::list<std::shared_ptr<Task>>& tasks,
+ const Settings& settings)
+{
+ bool ok{true};
+ std::cout << "Running unit-tests:\n";
+ // Run unit-tests
+ for(const auto& task : tasks)
+ {
+ if(task->targetType() == TargetType::UnitTest)
+ {
+ std::cout << task->name() << ": ";
+ auto ret = execute(task->target(), {}, false);
+ ok &= ret == 0;
+ if(ret == 0)
+ {
+ std::cout << "OK\n";
+ }
+ else
+ {
+ std::cout << "FAILED\n";
+ }
+ }
+ }
+
+ return ok ? 0 : 1;
+}