-
Notifications
You must be signed in to change notification settings - Fork 104
/
zproject_cucumber.gsl
153 lines (134 loc) · 4.89 KB
/
zproject_cucumber.gsl
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# Generates cucumber glue by adding
# * dependencies
# * selftest
# * make targets
# * CI integration
#
# This is a code generator built using the iMatix GSL code generation
# language. See https://github.com/zeromq/gsl for details.
#
# Copyright (c) the Contributors as noted in the AUTHORS file.
# This file is part of zproject.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
register_target ("cucumber", "Cucumber integration with cucumber-c")
function add_selftest ()
new project.main
define main.name = "$(project.prefix)_cucumber_selftest"
define main.private = "1"
endnew
endfunction
function add_step_definitions (target)
for my.target.step_defs
new project.class
define class.name = "$(step_defs.name)_step_defs"
define class.private = "1"
define class.type = "cucumber"
endnew
new project.main
define main.name = "$(step_defs.name)_step_runner"
define main.private = "1"
endnew
endfor
endfunction
function add_cucumber_c_dependency ()
new project.use
use.project = "cucumber"
use.optional = "1"
use.implied = "1"
endnew
endfunction
for project.target where target.name = "cucumber"
add_step_definitions (target)
add_selftest ()
add_cucumber_c_dependency ()
endfor
if count (project.target, target.name = "cucumber")
register_snippet("Makemodule", "cucumber")
register_snippet("CMakeLists_custom_targets", "cucumber")
endif
function snippet_makemodule_cucumber ()
>check-cucumber: src/$(project.prefix)_cucumber_selftest
>\t\$(LIBTOOL) --mode=execute \$(builddir)/src/$(project.prefix)_cucumber_selftest \$(builddir)/features
endfunction
function snippet_cmakelists_custom_targets_cucumber ()
>if (NOT TARGET test-cucumber)
> add_custom_target (
> test-cucumber
> COMMAND ${PROJECT_BINARY_DIR}/$(project.prefix)_cucumber_selftest ${PROJECT_SOURCE_DIR}/features
> )
>endif ()
endfunction
.macro generate_cucumber_selftest
.#
.# Build the project cucumber selftest program
.#
.output "src/$(project.prefix)_cucumber_selftest.$(project.source_ext)"
/* =========================================================================
$(project.prefix)_cucumber_selftest.c - run cucumber selftests
Runs cucumber steps servers and cucumber feature runner in one process
-------------------------------------------------------------------------
. for project.license
$(string.trim (license.):block )
. endfor
$(project.GENERATED_WARNING_HEADER:)
=========================================================================
*/
#include "$(project.prefix)_classes.$(project.header_ext)"
#if defined (HAVE_CUCUMBER)
#include <cucumber_c.h>
int main (int argc, char *argv [])
{
zargs_t *args = zargs_new (argc, argv);
zsock_t *client = zsock_new_router ("@tcp://127.0.0.1:8888");
assert (client);
zlist_t *step_runners = zlist_new ();
. for project.target where target.name = "cucumber"
. for target.step_defs
CREATE_STEP_RUNNER_ACTOR($(step_defs.name), $(step_defs.name)_state_new, $(step_defs.name)_state_destroy)
zlist_append (step_runners, $(step_defs.name)_steps_runner);
. endfor
. endfor
zlist_t *step_runner_identities = zlist_new ();
while (zlist_size (step_runner_identities) < zlist_size (step_runners)) {
zframe_t *identity;
char *command;
zsock_recv (client, "fs", &identity, &command);
if (streq (command, "HELLO")) {
zlist_append (step_runner_identities, identity);
}
zstr_free (&command);
}
const char *filename = zargs_first (args);
cucumber_feature_runner_t *feature_runner = cucumber_feature_runner_new (filename);
bool rc = cucumber_feature_runner_run (feature_runner, client, step_runner_identities);
zactor_t *step_runner = (zactor_t *) zlist_first (step_runners);
while (step_runner != NULL) {
zstr_send (step_runner, "$TERM");
zactor_destroy (&step_runner);
step_runner = (zactor_t *) zlist_next (step_runners);
}
zargs_destroy (&args);
zlist_destroy (&step_runners);;
zframe_t *identity = (zframe_t *) zlist_first (step_runner_identities);
while (identity) {
zframe_destroy (&identity);
identity = (zframe_t *) zlist_next (step_runner_identities);
}
zlist_destroy (&step_runner_identities);
zsock_destroy (&client);
cucumber_feature_runner_destroy (&feature_runner);
return rc ? 0 : 1;
}
/*
$(project.GENERATED_WARNING_HEADER:)
*/
#endif
.endmacro
function target_cucumber
if count (project.target, target.name = "cucumber")
generate_cucumber_selftest ()
endif
endfunction