summaryrefslogtreecommitdiff
path: root/src/unittest.cc
blob: 855a2ae5d068abac95317b17b3f07ed6dfdf9cc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// -*- c++ -*-
// Distributed under the BSD 2-Clause License.
// See accompanying file LICENSE for details.
#include "unittest.h"

#include <iostream>

#include "execute.h"
#include "task.h"

using namespace ctor;

int runUnitTests(std::set<std::shared_ptr<Task>>& tasks,
                 const Settings& settings)
{
	bool ok{true};
	std::cout << "Running unit-tests:" << std::endl;
	// Run unit-tests
	for(const auto& task : tasks)
	{
		if(task->targetType() == ctor::target_type::unit_test)
		{
			auto name = task->name();
			if(name.empty())
			{
				name = task->target();
			}
			std::cout << name << ": " << std::flush;
			auto ret = execute(task->targetFile(), {}, settings.verbose > 0);
			ok &= ret == 0;
			if(ret == 0)
			{
				std::cout << " OK" << std::endl;
			}
			else
			{
				std::cout << " FAILED" << std::endl;
			}
		}
	}

	return ok ? 0 : 1;
}