falsework 0.2.8 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/{lib/falsework/templates/naive/Gemfile.erb → Gemfile} +1 -1
  2. data/Gemfile.lock +12 -0
  3. data/README.rdoc +45 -21
  4. data/Rakefile +5 -5
  5. data/bin/falsework +64 -28
  6. data/doc/NEWS.rdoc +37 -10
  7. data/doc/README.rdoc +45 -21
  8. data/doc/TODO.org +13 -0
  9. data/doc/template-tutorial.rdoc +113 -0
  10. data/etc/falsework.yaml +1 -1
  11. data/lib/falsework/meta.rb +3 -2
  12. data/lib/falsework/mould.rb +267 -146
  13. data/lib/falsework/templates/c-glib/#config.yaml +18 -0
  14. data/lib/falsework/templates/c-glib/README +24 -0
  15. data/lib/falsework/templates/c-glib/doc/#doc.ascii +46 -0
  16. data/lib/falsework/templates/c-glib/doc/%%@project%%.1.asciidoc +46 -0
  17. data/lib/falsework/templates/{naive/doc/LICENSE.erb → c-glib/doc/LICENSE} +1 -1
  18. data/lib/falsework/templates/c-glib/doc/Makefile +17 -0
  19. data/lib/falsework/templates/c-glib/src/#exe.c +23 -0
  20. data/lib/falsework/templates/c-glib/src/#exe.h +8 -0
  21. data/lib/falsework/templates/c-glib/src/%%@project%%.c +23 -0
  22. data/lib/falsework/templates/c-glib/src/%%@project%%.h +26 -0
  23. data/lib/falsework/templates/c-glib/src/Makefile +28 -0
  24. data/lib/falsework/templates/c-glib/src/untest.c +9 -0
  25. data/lib/falsework/templates/c-glib/src/untest.h +14 -0
  26. data/lib/falsework/templates/c-glib/src/utils.c +232 -0
  27. data/lib/falsework/templates/c-glib/src/utils.h +45 -0
  28. data/lib/falsework/templates/c-glib/test/#test.c +48 -0
  29. data/lib/falsework/templates/c-glib/test/Makefile +78 -0
  30. data/lib/falsework/templates/c-glib/test/Makefile.test.mk +72 -0
  31. data/lib/falsework/templates/c-glib/test/mycat.c +8 -0
  32. data/{test/templates/.keep_me → lib/falsework/templates/c-glib/test/semis/text/empty.txt} +0 -0
  33. data/lib/falsework/templates/c-glib/test/test_utils.c +134 -0
  34. data/lib/falsework/templates/ruby-naive/#config.yaml +15 -0
  35. data/lib/falsework/templates/{naive/.gitignore.erb → ruby-naive/.gitignore.#erb} +0 -0
  36. data/lib/falsework/templates/ruby-naive/Gemfile +4 -0
  37. data/lib/falsework/templates/{naive/doc/README.rdoc.erb → ruby-naive/README.rdoc} +2 -2
  38. data/lib/falsework/templates/{naive/Rakefile.erb → ruby-naive/Rakefile} +1 -1
  39. data/lib/falsework/templates/{naive/bin/%%@project%%.erb → ruby-naive/bin/%%@project%%} +5 -5
  40. data/lib/falsework/templates/{naive/doc/#util.rdoc.erb → ruby-naive/doc/#doc.rdoc} +6 -6
  41. data/lib/falsework/templates/ruby-naive/doc/LICENSE +22 -0
  42. data/lib/falsework/templates/{naive/doc/NEWS.rdoc.erb → ruby-naive/doc/NEWS.rdoc} +0 -0
  43. data/lib/falsework/templates/{naive/README.rdoc.erb → ruby-naive/doc/README.rdoc} +2 -2
  44. data/lib/falsework/templates/{naive/etc/%%@project%%.yaml.erb → ruby-naive/etc/%%@project%%.yaml} +0 -0
  45. data/lib/falsework/templates/{naive/lib/%%@project%%/meta.rb.erb → ruby-naive/lib/%%@project%%/meta.rb} +3 -2
  46. data/lib/falsework/templates/{naive/lib/%%@project%%/trestle.rb.erb → ruby-naive/lib/%%@project%%/trestle.rb} +22 -14
  47. data/lib/falsework/templates/{naive/test/helper.rb.erb → ruby-naive/test/helper.rb} +0 -0
  48. data/lib/falsework/templates/{naive/test/helper_trestle.rb.erb → ruby-naive/test/helper_trestle.rb} +2 -2
  49. data/lib/falsework/templates/{naive/test/rake_git.rb.erb → ruby-naive/test/rake_git.rb} +1 -1
  50. data/lib/falsework/templates/{naive/test/test_%%@project%%.rb.erb → ruby-naive/test/test_%%@project%%.rb} +1 -1
  51. data/lib/falsework/trestle.rb +17 -9
  52. data/test/rake_erb_templates.rb +4 -4
  53. data/test/templates/config-01.yaml +2 -0
  54. data/test/test_cl.rb +29 -0
  55. data/test/test_exe.rb +61 -30
  56. data/test/test_mould.rb +80 -0
  57. metadata +86 -60
  58. data/doc/TODO.rdoc +0 -7
@@ -0,0 +1,18 @@
1
+ ---
2
+ :exe:
3
+ - :src: 'src/#exe.h'
4
+ :dest: 'src/%s.h'
5
+ :mode_int: null
6
+ - :src: 'src/#exe.c'
7
+ :dest: 'src/%s.c'
8
+ :mode_int: null
9
+
10
+ :doc:
11
+ - :src: 'doc/#doc.ascii'
12
+ :dest: 'doc/%s.1.asciidoc'
13
+ :mode_int: null
14
+
15
+ :test:
16
+ - :src: 'test/#test.c'
17
+ :dest: 'test/test_%s.c'
18
+ :mode_int: null
@@ -0,0 +1,24 @@
1
+ -*-text-*-
2
+
3
+ <%= @classy %> is a [TODO: write a description]
4
+
5
+
6
+ Requirements
7
+
8
+ Runtime:
9
+
10
+ * FreeBSD/Linux
11
+ * glib 2.x
12
+ * libiconv
13
+
14
+ Build:
15
+
16
+ * gcc 4.x
17
+ * GNU make
18
+ * asciidoc
19
+
20
+
21
+ Examples
22
+
23
+ % <%= @project %> -h
24
+ % <%= @project %>
@@ -0,0 +1,46 @@
1
+ // -*-doc-*-
2
+ <%= target.upcase %>(1)
3
+ <% target.size.times {|i| %>=<% } %>===
4
+ :doctype: manpage
5
+
6
+ NAME
7
+ ----
8
+
9
+ <%= target %> - [TODO: write a description]
10
+
11
+ SYNOPSIS
12
+ --------
13
+
14
+ *<%= target %>* [-q]
15
+
16
+ DESCRIPTION
17
+ -----------
18
+
19
+ <%= target %> is a [TODO: write a description]
20
+
21
+ OPTIONS
22
+ -------
23
+
24
+ *-q*::
25
+ Don't show warnings.
26
+
27
+
28
+ EXIT STATUS
29
+ -----------
30
+
31
+ Program exits 0 on success or >= 1 if en error occurs.
32
+
33
+ BUGS
34
+ ----
35
+
36
+ Probably.
37
+
38
+ SEE ALSO
39
+ --------
40
+
41
+ man(1), hier(7)
42
+
43
+ AUTHORS
44
+ -------
45
+
46
+ <%= @gecos %> <<%= @email %>>.
@@ -0,0 +1,46 @@
1
+ // -*-doc-*-
2
+ <%= @project.upcase %>(1)
3
+ <% @project.size.times {|i| %>=<% } %>===
4
+ :doctype: manpage
5
+
6
+ NAME
7
+ ----
8
+
9
+ <%= @project %> - [TODO: write a description]
10
+
11
+ SYNOPSIS
12
+ --------
13
+
14
+ *<%= @project %>* [-q]
15
+
16
+ DESCRIPTION
17
+ -----------
18
+
19
+ <%= @project %> is a [TODO: write a description]
20
+
21
+ OPTIONS
22
+ -------
23
+
24
+ *-q*::
25
+ Don't show warnings.
26
+
27
+
28
+ EXIT STATUS
29
+ -----------
30
+
31
+ Program exits 0 on success or >= 1 if en error occurs.
32
+
33
+ BUGS
34
+ ----
35
+
36
+ Probably.
37
+
38
+ SEE ALSO
39
+ --------
40
+
41
+ man(1), hier(7)
42
+
43
+ AUTHORS
44
+ -------
45
+
46
+ <%= @gecos %> <<%= @email %>>.
@@ -1,6 +1,6 @@
1
1
  (The MIT License)
2
2
 
3
- Copyright (c) 2010 <%= @gecos %>.
3
+ Copyright (c) <%= DateTime.now.year %> <%= @gecos %>.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -0,0 +1,17 @@
1
+ .PHONY : clean
2
+
3
+ MAN_ASCIIDOC := $(wildcard *.1.asciidoc)
4
+ MAN := $(patsubst %.1.asciidoc,%.1,$(wildcard *.1.asciidoc))
5
+
6
+ all: $(MAN)
7
+
8
+ %.1: %.1.asciidoc
9
+ a2x -f manpage $<
10
+
11
+ clean:
12
+ rm -f $(MAN)
13
+
14
+ # Debug. Use 'gmake p-obj' to print $(obj) variable.
15
+ p-%:
16
+ @echo $* = $($*)
17
+ @echo $*\'s origin is $(origin $*)
@@ -0,0 +1,23 @@
1
+ #include "<%= target %>.h"
2
+
3
+ int main(int argc, char **argv)
4
+ {
5
+ g_set_prgname(basename(argv[0]));
6
+
7
+ int exit_code = 0, ch;
8
+
9
+ while ((ch = getopt(argc, argv, "qh")) != -1) {
10
+ switch (ch) {
11
+ case 'q':
12
+ mylog_to(MYLOG_BITBUCKET);
13
+ break;
14
+ default:
15
+ printf("Usage: %s [-q]\n", argv[0]);
16
+ exit(1);
17
+ }
18
+ }
19
+ argc -= optind;
20
+ argv += optind;
21
+
22
+ return exit_code;
23
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef <%= uuid + '_' + target.upcase %>_H
2
+ #define <%= uuid + '_' + target.upcase %>_H
3
+
4
+ #include "<%= @project %>.h"
5
+
6
+
7
+
8
+ #endif // <%= uuid + '_' + target.upcase %>_H
@@ -0,0 +1,23 @@
1
+ #include "<%= @project %>.h"
2
+
3
+ int main(int argc, char **argv)
4
+ {
5
+ g_set_prgname(basename(argv[0]));
6
+
7
+ int exit_code = 0, ch;
8
+
9
+ while ((ch = getopt(argc, argv, "qh")) != -1) {
10
+ switch (ch) {
11
+ case 'q':
12
+ mylog_to(MYLOG_BITBUCKET);
13
+ break;
14
+ default:
15
+ printf("Usage: %s [-q]\n", argv[0]);
16
+ exit(1);
17
+ }
18
+ }
19
+ argc -= optind;
20
+ argv += optind;
21
+
22
+ return exit_code;
23
+ }
@@ -0,0 +1,26 @@
1
+ #ifndef <%= uuid + '_' + @project.upcase %>_H
2
+ #define <%= uuid + '_' + @project.upcase %>_H
3
+
4
+ #define PROG_NAME "<%= @project %>"
5
+ #define PROG_VER "0.0.1"
6
+
7
+ #include <errno.h>
8
+ #include <fcntl.h>
9
+ #include <libgen.h>
10
+ #include <pthread.h>
11
+ #include <signal.h>
12
+ #include <stdio.h>
13
+ #include <stdlib.h>
14
+ #include <string.h>
15
+ #include <sys/types.h>
16
+ #include <sys/stat.h>
17
+ #include <sys/uio.h>
18
+ #include <sys/wait.h>
19
+ #include <sys/param.h>
20
+ #include <unistd.h>
21
+
22
+ #include <glib.h>
23
+
24
+ #include "utils.h" // some goodies
25
+
26
+ #endif // <%= uuid + '_' + @project.upcase %>_H
@@ -0,0 +1,28 @@
1
+ gnome := glib-2.0
2
+
3
+ CFLAGS := -Wall -Wno-pointer-sign \
4
+ -I/usr/local/include \
5
+ $(shell pkg-config --cflags $(gnome) )
6
+
7
+ LDFLAGS := $(shell pkg-config --libs $(gnome) )
8
+
9
+ exe := <%= @project %>
10
+ obj := $(patsubst %.c,%.o,$(wildcard *.c))
11
+
12
+ .SECONDEXPANSION:
13
+
14
+ all: $(obj) $(exe)
15
+
16
+ $(obj): <%= @project %>.h
17
+
18
+ <%= @project %>.o: <%= @project %>.h
19
+
20
+ <%= @project %>: utils.o $$@.o
21
+ $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
22
+
23
+ clean:
24
+ rm -rf $(exe) $(obj) *.core
25
+
26
+ print-%:
27
+ @echo $* = $($*)
28
+ @echo $*\'s origin is $(origin $*)
@@ -0,0 +1,9 @@
1
+ #include "untest.h"
2
+
3
+ /* A callback handler for g_test_log_set_fatal_handler(). */
4
+ gboolean
5
+ mylog_fatal_handler(const gchar *log_domain, GLogLevelFlags log_level,
6
+ const gchar *message, gpointer user_data)
7
+ {
8
+ return FALSE;
9
+ }
@@ -0,0 +1,14 @@
1
+ #ifndef UNTEST_H
2
+ #define UNTEST_H
3
+
4
+ /*
5
+ Routines useful only for unit tests and glib's test framework.
6
+ */
7
+
8
+ #include "<%= @project %>.h"
9
+
10
+ gboolean
11
+ mylog_fatal_handler(const gchar *log_domain, GLogLevelFlags log_level,
12
+ const gchar *message, gpointer user_data);
13
+
14
+ #endif // UNTEST_H
@@ -0,0 +1,232 @@
1
+ #include <iconv.h>
2
+
3
+ #include "utils.h"
4
+
5
+ /* The result should be freed with g_free(). */
6
+ gchar *
7
+ text2utf8(const gchar *buf, const gchar *from) {
8
+ gsize br, bw;
9
+ if (!buf) return NULL;
10
+ if (!from) return (gchar*)buf;
11
+
12
+ if (g_regex_match_simple("utf.?8", from, G_REGEX_CASELESS, 0))
13
+ return g_strdup(buf); // prevent converting from utf8 to utf8
14
+ else
15
+ return g_convert_with_fallback(buf, -1, "UTF-8", from,
16
+ NULL, &br, &bw, NULL);
17
+ }
18
+
19
+ /*
20
+ Take a variable number of arguments and return the pointer to the
21
+ first non-NULL one. The argument list must end with &sentinel.
22
+ */
23
+ char
24
+ *first(char *first, ...)
25
+ {
26
+ va_list ap;
27
+ char *r = first;
28
+
29
+ va_start(ap, first);
30
+ while (!r) {
31
+ r = va_arg(ap, char*);
32
+ }
33
+ va_end(ap);
34
+
35
+ return r == &sentinel ? NULL : r;
36
+ }
37
+
38
+ /*
39
+ Read @fd till EOF and return the a null-terminated result with the
40
+ size of the string in @len (pass NULL if you're not interested).
41
+
42
+ The result should be freed with g_free().
43
+ */
44
+ gchar*
45
+ chan_read(int fd, gsize *len)
46
+ {
47
+ gsize n;
48
+ gchar buf[BUFSIZ];
49
+ gsize size = 0;
50
+ gchar *r = g_malloc((BUFSIZ+1) * sizeof *buf);
51
+
52
+ while ( (n = readn(fd, buf, BUFSIZ)) > 0) {
53
+ memmove(r+size, buf, n);
54
+ size += n;
55
+
56
+ gchar *tmp = g_realloc(r, (size+BUFSIZ+1) * sizeof *tmp);
57
+ if (!tmp) {
58
+ g_free(r);
59
+ g_warning("realloc failed");
60
+ size -= n;
61
+ break;
62
+ }
63
+ r = tmp;
64
+ }
65
+ r[size] = '\0';
66
+ if (len) *len = size;
67
+ return r;
68
+ }
69
+
70
+ gboolean
71
+ pr_exit_warn(const char *cmd, int status)
72
+ {
73
+ gboolean ok = TRUE;
74
+
75
+ if (WIFEXITED(status)) {
76
+ if (WEXITSTATUS(status) != 0) {
77
+ g_warning("%s: unexpected termination, exit status %d",
78
+ cmd, WEXITSTATUS(status));
79
+ ok = FALSE;
80
+ }
81
+ } else if (WIFSIGNALED(status)) {
82
+ g_warning("%s: abnormal termination, signal number %d",
83
+ cmd, WTERMSIG(status));
84
+ ok = FALSE;
85
+ } else if (WIFSTOPPED(status)) {
86
+ printf("%s: child stopped, signal number %d",
87
+ cmd, WSTOPSIG(status));
88
+ ok = FALSE;
89
+ }
90
+
91
+ return ok;
92
+ }
93
+
94
+ ssize_t /* Read "n" bytes from a descriptor. */
95
+ readn(int fd, void *vptr, size_t n)
96
+ {
97
+ size_t nleft;
98
+ ssize_t nread;
99
+ char *ptr;
100
+
101
+ ptr = vptr;
102
+ nleft = n;
103
+ while (nleft > 0) {
104
+ if ( (nread = read(fd, ptr, nleft)) < 0) {
105
+ if (errno == EINTR)
106
+ nread = 0; /* and call read() again */
107
+ else
108
+ return(-1);
109
+ } else if (nread == 0)
110
+ break; /* EOF */
111
+
112
+ nleft -= nread;
113
+ ptr += nread;
114
+ }
115
+ return(n - nleft); /* return >= 0 */
116
+ }
117
+
118
+ ssize_t /* Write "n" bytes to a descriptor. */
119
+ writen(int fd, const void *vptr, size_t n)
120
+ {
121
+ size_t nleft;
122
+ ssize_t nwritten;
123
+ const char *ptr;
124
+
125
+ ptr = vptr;
126
+ nleft = n;
127
+ while (nleft > 0) {
128
+ if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
129
+ if (nwritten < 0 && errno == EINTR)
130
+ nwritten = 0; /* and call write() again */
131
+ else
132
+ return(-1); /* error */
133
+ }
134
+
135
+ nleft -= nwritten;
136
+ ptr += nwritten;
137
+ }
138
+ return(n);
139
+ }
140
+
141
+ /*
142
+ Removes all leading & trailing whitespace + replaces \n, \t, \r to 1
143
+ space. Modifies @s in place.
144
+ */
145
+ GString*
146
+ my_strstrip(GString *s)
147
+ {
148
+ if (!s) return NULL;
149
+ GRegex *re = g_regex_new("[\n\r\t]+", 0, 0, NULL);
150
+ char *tmp = g_regex_replace_literal(re, s->str, s->len, 0, " ", 0, NULL);
151
+ g_regex_unref(re);
152
+
153
+ if (!tmp) return s;
154
+ g_strstrip(tmp);
155
+ g_string_assign(s, tmp);
156
+ g_free(tmp);
157
+ return s;
158
+ }
159
+
160
+ /* A callback handler for mylog_to(). */
161
+ void
162
+ mylog_to_devnull(const gchar *log_domain, GLogLevelFlags log_levels,
163
+ const gchar *message, gpointer user_data)
164
+ {
165
+ /* do nothing, eat all messages */
166
+ }
167
+
168
+ /*
169
+ Same as g_warning() + exit(1).
170
+ */
171
+ void myerr(const gchar *format, ...)
172
+ {
173
+ if (!format) {
174
+ g_warning("unspecified error");
175
+ exit(1);
176
+ }
177
+
178
+ va_list args;
179
+ va_start(args, format);
180
+ g_logv(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
181
+ va_end (args);
182
+
183
+ exit(1);
184
+ }
185
+
186
+ /*
187
+ Switch destination of logs according to @d.
188
+ */
189
+ void
190
+ mylog_to(MyLogDest d)
191
+ {
192
+ switch (d) {
193
+ case MYLOG_BITBUCKET:
194
+ g_log_set_handler(NULL, G_LOG_LEVEL_WARNING|G_LOG_LEVEL_CRITICAL,
195
+ mylog_to_devnull, NULL);
196
+ break;
197
+ case MYLOG_FILES:
198
+ g_error("MYLOG_FILES is unimplemented");
199
+ break;
200
+ default:
201
+ // reset ot glib's default
202
+ g_log_set_handler(NULL, G_LOG_LEVEL_WARNING|G_LOG_LEVEL_CRITICAL,
203
+ g_log_default_handler, NULL);
204
+ break;
205
+ }
206
+ }
207
+
208
+ /*
209
+ Do case insensitive regexp replace in @s in place.
210
+
211
+ Return FALSE on error. Warning: TRUE doens't mean that something was
212
+ actually replaced.
213
+ */
214
+ gboolean
215
+ my_regsub(GString* s, const gchar *re, const gchar *sub)
216
+ {
217
+ if (!s || !re || !sub) return FALSE;
218
+ gboolean r = FALSE;
219
+ GError *e = NULL;
220
+
221
+ GRegex *pattern = g_regex_new(re, G_REGEX_CASELESS|G_REGEX_MULTILINE, 0, NULL);
222
+ char *t = g_regex_replace(pattern, s->str, -1, 0, sub, 0, &e);
223
+ if (e == NULL && t) {
224
+ g_string_assign(s, t);
225
+ r = TRUE;
226
+ }
227
+
228
+ g_regex_unref(pattern);
229
+ g_free(t);
230
+ g_clear_error(&e);
231
+ return r;
232
+ }