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,45 @@
1
+ #ifndef UTILS_H
2
+ #define UTILS_H
3
+
4
+ #include <errno.h>
5
+ #include <stdio.h>
6
+ #include <string.h>
7
+ #include <sys/types.h>
8
+ #include <sys/param.h>
9
+ #include <sys/uio.h>
10
+ #include <sys/wait.h>
11
+ #include <unistd.h>
12
+ #include <stdlib.h>
13
+ #include <limits.h>
14
+
15
+ #include <glib.h>
16
+
17
+ /* Logging destination */
18
+ typedef enum _MyLogDest {
19
+ MYLOG_CONSOLE,
20
+ MYLOG_FILES,
21
+ MYLOG_BITBUCKET
22
+ } MyLogDest;
23
+
24
+ /* Used with first(), because of its address is unique among other
25
+ pointers. */
26
+ char sentinel;
27
+
28
+ gchar *text2utf8(const gchar *buf, const gchar *from);
29
+ char *first(char *first, ...);
30
+ gchar* chan_read(int fd, gsize *len);
31
+
32
+ gboolean pr_exit_warn(const char *cmd, int status);
33
+
34
+ GString* my_strstrip(GString *s);
35
+ gboolean my_regsub(GString* s, const gchar *re, const gchar *sub);
36
+
37
+ void mylog_to(MyLogDest d);
38
+ void mylog_to_devnull(const gchar *log_domain, GLogLevelFlags log_levels,
39
+ const gchar *message, gpointer user_data);
40
+ void myerr(const gchar *format, ...);
41
+
42
+ ssize_t readn(int fd, void *vptr, size_t n);
43
+ ssize_t writen(int fd, const void *vptr, size_t n);
44
+
45
+ #endif // UTILS_H
@@ -0,0 +1,48 @@
1
+ #include "untest.h"
2
+
3
+ typedef struct {
4
+ gchar *s;
5
+ } <%= target_camelcase %>Fixture;
6
+
7
+ void
8
+ <%= target %>_fixture_setup(<%= target_camelcase %>Fixture *fix, gconstpointer test_file)
9
+ {
10
+ // don't freak out on g_warning()
11
+ g_test_log_set_fatal_handler(mylog_fatal_handler, NULL);
12
+
13
+ fix->s = g_strdup("hey");
14
+ }
15
+
16
+ void
17
+ <%= target %>_fixture_teardown(<%= target_camelcase %>Fixture *fix, gconstpointer test_file)
18
+ {
19
+ g_free(fix->s);
20
+ }
21
+
22
+ void
23
+ test_foo()
24
+ {
25
+ g_test_log_set_fatal_handler(mylog_fatal_handler, NULL);
26
+
27
+ g_assert_cmpstr("zzz", ==, "zzz");
28
+ }
29
+
30
+ void
31
+ test_bar(<%= target_camelcase %>Fixture *fix,
32
+ gconstpointer test_file)
33
+ {
34
+ g_assert_cmpstr("hey", ==, fix->s);
35
+ }
36
+
37
+ int
38
+ main (int argc, char **argv)
39
+ {
40
+ g_test_init(&argc, &argv, NULL);
41
+
42
+ g_test_add_func("/<%= target %>/foo", test_foo);
43
+
44
+ g_test_add("/<%= target %>/bar", <%= target_camelcase %>Fixture, "some data",
45
+ <%= target %>_fixture_setup, test_bar, <%= target %>_fixture_teardown);
46
+
47
+ return g_test_run();
48
+ }
@@ -0,0 +1,78 @@
1
+ # -*- makefile -*-
2
+
3
+ # All tests file names must be in test_xxx.c format. If your tests leave
4
+ # temporal files, add them to GARBAGE variable below.
5
+ #
6
+ # Any xxx.c file will be compiled in xxx file. If you need compile some
7
+ # xxx.c file before running tests, add xxx to TEST_UTILS variable below.
8
+ #
9
+ #
10
+ # Targets:
11
+ #
12
+ # test -- run tests
13
+ # tests -- compile tests
14
+ # exe -- compile *.c files except tests
15
+
16
+ where-am-i = $(CURDIR)/$(lastword $(MAKEFILE_LIST))
17
+ mk_location := $(realpath $(call where-am-i))
18
+ mk_dir := $(dir $(mk_location))
19
+
20
+ GARBAGE :=
21
+
22
+ gnome := glib-2.0
23
+
24
+ # main source tree
25
+ proj_src := $(mk_dir)../src
26
+ VPATH := $(proj_src)
27
+
28
+ CFLAGS := -Wall -Wno-pointer-sign -std=c99 -fPIC -pedantic \
29
+ -I$(proj_src) \
30
+ $(shell pkg-config --cflags $(gnome) ) \
31
+ -I/usr/local/include
32
+
33
+ LDFLAGS := $(shell pkg-config --libs $(gnome) )
34
+
35
+ # in this dir
36
+ tests := $(basename $(wildcard test_*.c) )
37
+ exe := $(filter-out $(tests),$(basename $(wildcard *.c)) )
38
+
39
+ # in the source tree
40
+ obj_srcall := $(notdir $(patsubst %.c,%.o,$(wildcard $(proj_src)/*.c)) )
41
+ # c files with main function in them
42
+ src_exe = $(shell ruby -e 'ARGV.each {|i| print(File.basename(i)+" ") if File.read(i) =~ /[[:space:];]*(int|void)\s+main\s*\([^)(]*\)\s*{/ }' $(proj_src)/*.c )
43
+ # exclude $src_exe from to be compiled .o files
44
+ obj_srcexe := $(patsubst %.c,%.o,$(src_exe)) <%= @project %>.o
45
+ obj_src := $(filter-out $(obj_srcexe),$(obj_srcall))
46
+ src_h := $(patsubst %.c,%.o,$(wildcard $(proj_src)/*.h))
47
+
48
+ # generate test targets for glib test framework
49
+ TEST_PROGS := $(tests)
50
+ # execs required for tests
51
+ TEST_UTILS := mycat
52
+
53
+ .SECONDEXPANSION:
54
+
55
+ .PHONY: tests exe clean
56
+
57
+ all: tests
58
+
59
+ tests: $(tests)
60
+ exe: $(exe)
61
+
62
+ $(tests): $$@.o $(obj_src)
63
+ $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
64
+
65
+ $(obj_src): $(src_h)
66
+
67
+ $(exe): $$@.o $(obj_src)
68
+ $(CC) $^ -o $@ $(CFLAGS) $(LDFLAGS)
69
+
70
+ include $(mk_dir)/Makefile.test.mk
71
+
72
+ clean:
73
+ rm -rf *.core $(tests) $(tests:=.o) \
74
+ $(exe) $(exe:=.o) $(obj_src) $(GARBAGE)
75
+
76
+ print-%:
77
+ @echo $* = $($*)
78
+ @echo $*\'s origin is $(origin $*)
@@ -0,0 +1,72 @@
1
+ # -*- makefile -*-
2
+
3
+ GARBAGE += test-report.xml full-report.html full-report.xml
4
+
5
+ GTESTER = gtester
6
+ GTESTER_REPORT = gtester-report
7
+
8
+ # initialize variables for unconditional += appending
9
+ EXTRA_DIST +=
10
+ TEST_PROGS +=
11
+
12
+ ### testing rules
13
+
14
+ # test: run all tests in cwd and subdirs
15
+ test: $(TEST_UTILS) $(tests) test-nonrecursive
16
+ @ for subdir in $(SUBDIRS) . ; do \
17
+ test "$$subdir" = "." -o "$$subdir" = "po" || \
18
+ ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
19
+ done
20
+
21
+ # test-nonrecursive: run tests only in cwd
22
+ test-nonrecursive: ${TEST_PROGS}
23
+ @test -z "${TEST_PROGS}" || MALLOC_CHECK_=2 MALLOC_PERTURB_=$$(($${RANDOM:-256} % 256)) ${GTESTER} --verbose ${TEST_PROGS}
24
+
25
+ # test-report: run tests in subdirs and generate report
26
+ # perf-report: run tests in subdirs with -m perf and generate report
27
+ # full-report: like test-report: with -m perf and -m slow
28
+ test-report perf-report full-report: ${TEST_PROGS}
29
+ @test -z "${TEST_PROGS}" || { \
30
+ case $@ in \
31
+ test-report) test_options="-k";; \
32
+ perf-report) test_options="-k -m=perf";; \
33
+ full-report) test_options="-k -m=perf -m=slow";; \
34
+ esac ; \
35
+ if test -z "$$GTESTER_LOGDIR" ; then \
36
+ ${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
37
+ elif test -n "${TEST_PROGS}" ; then \
38
+ ${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
39
+ fi ; \
40
+ }
41
+ @ ignore_logdir=true ; \
42
+ if test -z "$$GTESTER_LOGDIR" ; then \
43
+ GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
44
+ ignore_logdir=false ; \
45
+ fi ; \
46
+ if test -d "$(top_srcdir)/.git" ; then \
47
+ REVISION=`git describe` ; \
48
+ else \
49
+ REVISION=$(VERSION) ; \
50
+ fi ; \
51
+ for subdir in $(SUBDIRS) . ; do \
52
+ test "$$subdir" = "." -o "$$subdir" = "po" || \
53
+ ( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
54
+ done ; \
55
+ $$ignore_logdir || { \
56
+ echo '<?xml version="1.0"?>' > $@.xml ; \
57
+ echo '<report-collection>' >> $@.xml ; \
58
+ echo '<info>' >> $@.xml ; \
59
+ echo ' <package>$(PACKAGE)</package>' >> $@.xml ; \
60
+ echo ' <version>$(VERSION)</version>' >> $@.xml ; \
61
+ echo " <revision>$$REVISION</revision>" >> $@.xml ; \
62
+ echo '</info>' >> $@.xml ; \
63
+ for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
64
+ sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
65
+ done ; \
66
+ echo >> $@.xml ; \
67
+ echo '</report-collection>' >> $@.xml ; \
68
+ rm -rf "$$GTESTER_LOGDIR"/ ; \
69
+ ${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
70
+ }
71
+
72
+ .PHONY: test test-report perf-report full-report test-nonrecursive
@@ -0,0 +1,8 @@
1
+ #include "<%= @project %>.h"
2
+
3
+ int main()
4
+ {
5
+ char *s = chan_read(fileno(stdin), NULL);
6
+ fputs(s, stdout);
7
+ return 0;
8
+ }
@@ -0,0 +1,134 @@
1
+ #include "untest.h"
2
+
3
+ void test_text2utf8()
4
+ {
5
+ char *ru_utf8 = "\u0430\u0439\u043D\u044D\u043D\u044D";
6
+ char *ru_1251 = "\xE0\xE9\xED\xFD\xED\xFD";
7
+
8
+ char *r = text2utf8(ru_1251, "windows-1251");
9
+ g_assert(strcmp(r, ru_utf8) == 0);
10
+ g_free(r);
11
+
12
+ r = text2utf8(ru_utf8, "UTF-8");
13
+ g_assert(strcmp(r, ru_utf8) == 0);
14
+ g_free(r);
15
+
16
+ g_assert_cmpstr(ru_1251, ==, text2utf8(ru_1251, NULL));
17
+ g_assert_cmpstr(NULL, ==, text2utf8(NULL, "windows-1251"));
18
+ g_assert_cmpstr(NULL, ==, text2utf8(NULL, NULL));
19
+ }
20
+
21
+ void
22
+ test_my_strstrip()
23
+ {
24
+ GString *s = g_string_new("");
25
+
26
+ g_assert(!my_strstrip(NULL));
27
+
28
+ char *t1[] = { "q", "\t q\t", "\t\n\n q\t\n\r", NULL };
29
+ char **p;
30
+ for (p = t1; *p; ++p) {
31
+ g_string_assign(s, *p);
32
+ my_strstrip(s);
33
+ g_assert_cmpstr(s->str, ==, "q");
34
+ g_assert_cmpint(s->len, ==, strlen("q"));
35
+ }
36
+
37
+ char *t2[] = { "", "\t \t", " ", NULL };
38
+ for (p = t2; *p; ++p) {
39
+ g_string_assign(s, *p);
40
+ my_strstrip(s);
41
+ g_assert_cmpstr(s->str, ==, "");
42
+ g_assert_cmpint(s->len, ==, 0);
43
+ }
44
+
45
+ g_string_assign(s, "This is\na text & only text.");
46
+ my_strstrip(s);
47
+ g_assert_cmpstr("This is a text & only text.", ==, s->str);
48
+
49
+ g_string_free(s, TRUE);
50
+ }
51
+
52
+ void
53
+ test_first()
54
+ {
55
+ char *q = NULL;
56
+ char *w = NULL;
57
+ char *e = "zzz";
58
+ char *r = NULL;
59
+
60
+ g_assert(first(q, w, e, r, &sentinel) == e);
61
+ g_assert(first(r, e, w, q, &sentinel) == e); // reverse
62
+ g_assert(first(e, &sentinel) == e);
63
+ g_assert(first(e, q, w, r, &sentinel) == e);
64
+ g_assert(first(q, w, r, e, &sentinel) == e);
65
+ g_assert(first(q, w, r, &sentinel) == NULL);
66
+ g_assert(first(q, &sentinel) == NULL);
67
+ g_assert(first(NULL, &sentinel) == NULL);
68
+ g_assert(first(NULL, NULL, &sentinel) == NULL);
69
+ }
70
+
71
+ void
72
+ test_chan_read()
73
+ {
74
+ struct Cmd {
75
+ char *c;
76
+ gsize bytes;
77
+ char *md5;
78
+ } cmd[] = {
79
+ { "./mycat < semis/text/empty.txt", 0, "d41d8cd98f00b204e9800998ecf8427e" },
80
+ { "./mycat < Makefile.test.mk", 2753, "f25fbc27b05cf7a33b6d01eb5a0bedb9" },
81
+ // delete this line if you don't have wordnet installed
82
+ { "./mycat < /usr/local/share/WordNet/data.noun", 15300280, "a51f8a16db5be01db3ae95367469c6c7" },
83
+ { NULL, -1, NULL }
84
+ };
85
+
86
+ struct Cmd *p;
87
+ for (p = cmd; p->c; ++p) {
88
+ FILE* f = popen(p->c, "r");
89
+ g_assert(f);
90
+
91
+ char buf[p->bytes];
92
+ gsize bytes = readn(fileno(f), buf, p->bytes);
93
+ pclose(f);
94
+
95
+ g_assert_cmpint(p->bytes, ==, bytes);
96
+ gchar *md5 = g_compute_checksum_for_string(G_CHECKSUM_MD5, buf, p->bytes);
97
+ g_assert_cmpstr(p->md5, ==, md5);
98
+ g_free(md5);
99
+ }
100
+ }
101
+
102
+ void
103
+ test_mylog_set()
104
+ {
105
+ mylog_to(MYLOG_BITBUCKET);
106
+ if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) {
107
+ g_message("so you say you like logs");
108
+ exit(0); // successful test run
109
+ }
110
+ g_test_trap_assert_passed();
111
+ g_test_trap_assert_stderr(NULL);
112
+
113
+ mylog_to(MYLOG_CONSOLE);
114
+ if (g_test_trap_fork(0, G_TEST_TRAP_SILENCE_STDERR)) {
115
+ g_message("so you say you like logs");
116
+ exit(0); // successful test run
117
+ }
118
+ g_test_trap_assert_passed();
119
+ g_test_trap_assert_stderr("*so you say you like logs*");
120
+ }
121
+
122
+ int
123
+ main (int argc, char **argv)
124
+ {
125
+ g_test_init (&argc, &argv, NULL);
126
+
127
+ g_test_add_func("/utils/text2utf8", test_text2utf8);
128
+ g_test_add_func("/utils/my_strstrip", test_my_strstrip);
129
+ g_test_add_func("/utils/first", test_first);
130
+ g_test_add_func("/utils/chan_read", test_chan_read);
131
+ g_test_add_func("/utils/mylog_set", test_mylog_set);
132
+
133
+ return g_test_run();
134
+ }
@@ -0,0 +1,15 @@
1
+ ---
2
+ :exe:
3
+ - :src: 'bin/%%@project%%'
4
+ :dest: 'bin/%s'
5
+ :mode_int: 0744
6
+
7
+ :doc:
8
+ - :src: 'doc/#doc.rdoc'
9
+ :dest: 'doc/%s.rdoc'
10
+ :mode_int: null
11
+
12
+ :test:
13
+ - :src: 'test/test_%%@project%%.rb'
14
+ :dest: 'test/test_%s.rb'
15
+ :mode_int: null
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "open4", "~>1.2.0"
4
+ gem "git", "~>1.2.5"
@@ -1,6 +1,6 @@
1
1
  =Name
2
2
 
3
- <%= @project %>-- [TODO: write a summary here.]
3
+ <%= @classy %>--[TODO: write a summary here.]
4
4
 
5
5
 
6
6
  ==Synopsis
@@ -51,6 +51,6 @@ gemdir`/gems/<%= @project %>-x.y.z/etc/</tt> directory for samples.
51
51
 
52
52
  ==Examples
53
53
 
54
- % ri <%= @project.capitalize %>
54
+ % ri <%= @camelcase %>
55
55
  % <%= @project %> --config-dirs
56
56
  % <%= @project %> -V
@@ -9,7 +9,7 @@ gem 'rdoc'
9
9
  require 'rdoc/task'
10
10
 
11
11
  require_relative 'lib/<%= @project %>/meta'
12
- include <%= @project.capitalize %>
12
+ include <%= @camelcase %>
13
13
 
14
14
  require_relative 'test/rake_git'
15
15