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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/**
* \file host_run_tests.cpp
* \brief Automated test for the host script execution logic.
* \author Copyright (c) 2008 Jason Perkins and the Premake project
*/
#include "premake.h"
#include "testing/testing.h"
extern "C" {
#include "host/host.h"
#include "base/dir.h"
#include "base/error.h"
}
/* Mock steps for testing host_run_steps */
static int num_step_calls;
static int MockStepOkay(Session sess)
{
sess = 0;
num_step_calls++;
return OKAY;
}
static int MockStepFail(Session sess)
{
sess = 0;
return !OKAY;
}
struct FxHostRun
{
Session sess;
FxHostRun()
{
num_step_calls = 0;
sess = session_create();
dir_set_current("testing/test_files");
}
~FxHostRun()
{
dir_set_current("../..");
session_destroy(sess);
error_clear();
}
};
SUITE(host)
{
/**********************************************************************
* host_run_script() tests
**********************************************************************/
TEST_FIXTURE(FxHostRun, HostRunScript_ReturnsOkay_OnSuccess)
{
int result = host_run_script(sess);
CHECK(result == OKAY);
}
TEST_FIXTURE(FxHostRun, HostRunScript_RunsDefaultFile_OnNoFileArg)
{
host_run_script(sess);
const char* result = session_run_string(sess,
"return script_has_run");
CHECK_EQUAL("true", result);
}
/**********************************************************************
* host_run_steps() tests
**********************************************************************/
TEST_FIXTURE(FxHostRun, HostRunSteps_ReturnsOkay_OnAllStepsSucceed)
{
HostExecutionStep steps[] = { MockStepOkay, NULL };
int result = host_run_steps(sess, steps);
CHECK(result == OKAY);
}
TEST_FIXTURE(FxHostRun, HostRunSteps_RunsAllSteps)
{
HostExecutionStep steps[] = { MockStepOkay, MockStepOkay, MockStepOkay, NULL };
host_run_steps(sess, steps);
CHECK(num_step_calls == 3);
}
TEST_FIXTURE(FxHostRun, HostRunSteps_ReturnsNotOkay_OnError)
{
HostExecutionStep steps[] = { MockStepFail, NULL };
int result = host_run_steps(sess, steps);
CHECK(result != OKAY);
}
TEST_FIXTURE(FxHostRun, HostRunSteps_StopsRunning_OnError)
{
HostExecutionStep steps[] = { MockStepOkay, MockStepFail, MockStepOkay, NULL };
host_run_steps(sess, steps);
CHECK(num_step_calls == 1);
}
/**********************************************************************
* host_run_action() tests
**********************************************************************/
TEST_FIXTURE(FxHostRun, HostRunAction_ReturnsNotOkay_OnInvalidAction)
{
const char* argv[] = { "premake", "nonesuch", NULL };
host_set_argv(argv);
int result = host_run_action(sess);
CHECK(result != OKAY);
}
TEST_FIXTURE(FxHostRun, HostRunAction_SetsError_OnInvalidAction)
{
const char* argv[] = { "premake", "nonesuch", NULL };
host_set_argv(argv);
host_run_action(sess);
CHECK_EQUAL("invalid action 'nonesuch'", error_get());
}
}
|