diff options
| author | Paul Eggert | 2015-11-19 11:31:45 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-11-19 11:32:21 -0800 |
| commit | c8a972b0c3082edfcca4a85562224499f75bfe9b (patch) | |
| tree | 6266e9c2d1d168e49ef6de34e800435162cca2d4 /modules | |
| parent | 7cd728c813f2c472a2f6a0cb0c3fb3ee46c9d8ad (diff) | |
| download | emacs-c8a972b0c3082edfcca4a85562224499f75bfe9b.tar.gz emacs-c8a972b0c3082edfcca4a85562224499f75bfe9b.zip | |
Style fixes for indenting etc. in module code
This is mostly indenting and spacing changes. Also, remove
some unnecessary static decls instead of bothering to reindent them.
* src/module.h (EMACS_EXTERN_C_BEGIN): Remove, and do this inline,
as most other Emacs files do for this sort of thing.
Diffstat (limited to 'modules')
| -rw-r--r-- | modules/mod-test/mod-test.c | 177 | ||||
| -rw-r--r-- | modules/mod-test/test.el | 16 | ||||
| -rwxr-xr-x | modules/modhelp.py | 31 |
3 files changed, 114 insertions, 110 deletions
diff --git a/modules/mod-test/mod-test.c b/modules/mod-test/mod-test.c index 04b6122cafb..b58b86c9047 100644 --- a/modules/mod-test/mod-test.c +++ b/modules/mod-test/mod-test.c | |||
| @@ -23,24 +23,21 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ | |||
| 23 | 23 | ||
| 24 | int plugin_is_GPL_compatible; | 24 | int plugin_is_GPL_compatible; |
| 25 | 25 | ||
| 26 | /* | 26 | /* Always return symbol 't'. */ |
| 27 | * Always return symbol 't' | 27 | static emacs_value |
| 28 | */ | 28 | Fmod_test_return_t (emacs_env *env, int nargs, emacs_value args[], void *data) |
| 29 | static emacs_value Fmod_test_return_t (emacs_env *env, int nargs, emacs_value args[], void *data) | ||
| 30 | { | 29 | { |
| 31 | return env->intern (env, "t"); | 30 | return env->intern (env, "t"); |
| 32 | } | 31 | } |
| 33 | 32 | ||
| 34 | 33 | /* Expose simple sum function. */ | |
| 35 | /* | ||
| 36 | * Expose simple sum function | ||
| 37 | */ | ||
| 38 | static int64_t sum (int64_t a, int64_t b) | 34 | static int64_t sum (int64_t a, int64_t b) |
| 39 | { | 35 | { |
| 40 | return a + b; | 36 | return a + b; |
| 41 | } | 37 | } |
| 42 | 38 | ||
| 43 | static emacs_value Fmod_test_sum (emacs_env *env, int nargs, emacs_value args[], void* data) | 39 | static emacs_value |
| 40 | Fmod_test_sum (emacs_env *env, int nargs, emacs_value args[], void *data) | ||
| 44 | { | 41 | { |
| 45 | int64_t a = env->extract_integer (env, args[0]); | 42 | int64_t a = env->extract_integer (env, args[0]); |
| 46 | int64_t b = env->extract_integer (env, args[1]); | 43 | int64_t b = env->extract_integer (env, args[1]); |
| @@ -51,38 +48,40 @@ static emacs_value Fmod_test_sum (emacs_env *env, int nargs, emacs_value args[], | |||
| 51 | } | 48 | } |
| 52 | 49 | ||
| 53 | 50 | ||
| 54 | /* | 51 | /* Signal '(error 56). */ |
| 55 | * Signal '(error 56) | 52 | static emacs_value |
| 56 | */ | 53 | Fmod_test_signal (emacs_env *env, int nargs, emacs_value args[], void *data) |
| 57 | static emacs_value Fmod_test_signal (emacs_env *env, int nargs, emacs_value args[], void* data) | ||
| 58 | { | 54 | { |
| 59 | assert (env->non_local_exit_check (env) == emacs_funcall_exit_return); | 55 | assert (env->non_local_exit_check (env) == emacs_funcall_exit_return); |
| 60 | env->non_local_exit_signal (env, env->intern (env, "error"), env->make_integer (env, 56)); | 56 | env->non_local_exit_signal (env, env->intern (env, "error"), |
| 57 | env->make_integer (env, 56)); | ||
| 61 | return NULL; | 58 | return NULL; |
| 62 | } | 59 | } |
| 63 | 60 | ||
| 64 | 61 | ||
| 65 | /* | 62 | /* Throw '(tag 65). */ |
| 66 | * Throw '(tag 65) | 63 | static emacs_value |
| 67 | */ | 64 | Fmod_test_throw (emacs_env *env, int nargs, emacs_value args[], void *data) |
| 68 | static emacs_value Fmod_test_throw (emacs_env *env, int nargs, emacs_value args[], void* data) | ||
| 69 | { | 65 | { |
| 70 | assert (env->non_local_exit_check (env) == emacs_funcall_exit_return); | 66 | assert (env->non_local_exit_check (env) == emacs_funcall_exit_return); |
| 71 | env->non_local_exit_throw (env, env->intern (env, "tag"), env->make_integer (env, 65)); | 67 | env->non_local_exit_throw (env, env->intern (env, "tag"), |
| 68 | env->make_integer (env, 65)); | ||
| 72 | return NULL; | 69 | return NULL; |
| 73 | } | 70 | } |
| 74 | 71 | ||
| 75 | 72 | ||
| 76 | /* | 73 | /* Call argument function, catch all non-local exists and return |
| 77 | * Call argument function, catch all non-local exists and return | 74 | either normal result or a list describing the non-local exit. */ |
| 78 | * either normal result or a list describing the non-local exit. | 75 | static emacs_value |
| 79 | */ | 76 | Fmod_test_non_local_exit_funcall (emacs_env *env, int nargs, emacs_value args[], |
| 80 | static emacs_value Fmod_test_non_local_exit_funcall (emacs_env *env, int nargs, emacs_value args[], void* data) | 77 | void *data) |
| 81 | { | 78 | { |
| 82 | assert (nargs == 1); | 79 | assert (nargs == 1); |
| 83 | const emacs_value result = env->funcall (env, args[0], 0, NULL); | 80 | const emacs_value result = env->funcall (env, args[0], 0, NULL); |
| 84 | emacs_value non_local_exit_symbol, non_local_exit_data; | 81 | emacs_value non_local_exit_symbol, non_local_exit_data; |
| 85 | enum emacs_funcall_exit code = env->non_local_exit_get (env, &non_local_exit_symbol, &non_local_exit_data); | 82 | enum emacs_funcall_exit code |
| 83 | = env->non_local_exit_get (env, &non_local_exit_symbol, | ||
| 84 | &non_local_exit_data); | ||
| 86 | switch (code) | 85 | switch (code) |
| 87 | { | 86 | { |
| 88 | case emacs_funcall_exit_return: | 87 | case emacs_funcall_exit_return: |
| @@ -91,141 +90,133 @@ static emacs_value Fmod_test_non_local_exit_funcall (emacs_env *env, int nargs, | |||
| 91 | { | 90 | { |
| 92 | env->non_local_exit_clear (env); | 91 | env->non_local_exit_clear (env); |
| 93 | const emacs_value Flist = env->intern (env, "list"); | 92 | const emacs_value Flist = env->intern (env, "list"); |
| 94 | emacs_value list_args[] = {env->intern (env, "signal"), non_local_exit_symbol, non_local_exit_data}; | 93 | emacs_value list_args[] = {env->intern (env, "signal"), |
| 94 | non_local_exit_symbol, non_local_exit_data}; | ||
| 95 | return env->funcall (env, Flist, 3, list_args); | 95 | return env->funcall (env, Flist, 3, list_args); |
| 96 | } | 96 | } |
| 97 | case emacs_funcall_exit_throw: | 97 | case emacs_funcall_exit_throw: |
| 98 | { | 98 | { |
| 99 | env->non_local_exit_clear (env); | 99 | env->non_local_exit_clear (env); |
| 100 | const emacs_value Flist = env->intern (env, "list"); | 100 | const emacs_value Flist = env->intern (env, "list"); |
| 101 | emacs_value list_args[] = {env->intern (env, "throw"), non_local_exit_symbol, non_local_exit_data}; | 101 | emacs_value list_args[] = {env->intern (env, "throw"), |
| 102 | non_local_exit_symbol, non_local_exit_data}; | ||
| 102 | return env->funcall (env, Flist, 3, list_args); | 103 | return env->funcall (env, Flist, 3, list_args); |
| 103 | } | 104 | } |
| 104 | } | 105 | } |
| 105 | /* never reached */ | 106 | |
| 107 | /* Never reached. */ | ||
| 106 | return env->intern (env, "nil");; | 108 | return env->intern (env, "nil");; |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | 111 | ||
| 110 | /* | 112 | /* Return a global referrence. */ |
| 111 | * Return a global referrence | 113 | static emacs_value |
| 112 | */ | 114 | Fmod_test_globref_make (emacs_env *env, int nargs, emacs_value args[], |
| 113 | static emacs_value Fmod_test_globref_make (emacs_env *env, int nargs, emacs_value args[], void* data) | 115 | void *data) |
| 114 | { | 116 | { |
| 115 | /* make a big string and make it global */ | 117 | /* Make a big string and make it global. */ |
| 116 | size_t i; | 118 | char str[26 * 100]; |
| 117 | char str[26*100]; | 119 | for (size_t i = 0; i < sizeof str; i++) |
| 118 | 120 | str[i] = 'a' + (i % 26); | |
| 119 | for (i = 0; i < sizeof (str); i++) | ||
| 120 | { | ||
| 121 | str[i] = 'a' + (i % 26); | ||
| 122 | } | ||
| 123 | 121 | ||
| 124 | /* we don't need to null-terminate str */ | 122 | /* We don't need to null-terminate str. */ |
| 125 | emacs_value lisp_str = env->make_string (env, str, sizeof (str)); | 123 | emacs_value lisp_str = env->make_string (env, str, sizeof str); |
| 126 | return env->make_global_ref (env, lisp_str); | 124 | return env->make_global_ref (env, lisp_str); |
| 127 | } | 125 | } |
| 128 | 126 | ||
| 129 | 127 | ||
| 130 | /* | 128 | /* Return a copy of the argument string where every 'a' is replaced |
| 131 | * Return a copy of the argument string where every 'a' is replaced with 'b'. | 129 | with 'b'. */ |
| 132 | */ | 130 | static emacs_value |
| 133 | static emacs_value Fmod_test_string_a_to_b (emacs_env *env, int nargs, emacs_value args[], void* data) | 131 | Fmod_test_string_a_to_b (emacs_env *env, int nargs, emacs_value args[], |
| 132 | void *data) | ||
| 134 | { | 133 | { |
| 135 | emacs_value lisp_str = args[0]; | 134 | emacs_value lisp_str = args[0]; |
| 136 | size_t size = 0; | 135 | size_t size = 0; |
| 137 | char * buf = NULL; | 136 | char * buf = NULL; |
| 138 | size_t i; | ||
| 139 | 137 | ||
| 140 | env->copy_string_contents (env, lisp_str, buf, &size); | 138 | env->copy_string_contents (env, lisp_str, buf, &size); |
| 141 | buf = malloc (size); | 139 | buf = malloc (size); |
| 142 | env->copy_string_contents (env, lisp_str, buf, &size); | 140 | env->copy_string_contents (env, lisp_str, buf, &size); |
| 143 | 141 | ||
| 144 | for (i = 0; i+1 < size; i++) { | 142 | for (size_t i = 0; i + 1 < size; i++) |
| 145 | if (buf[i] == 'a') | 143 | if (buf[i] == 'a') |
| 146 | buf[i] = 'b'; | 144 | buf[i] = 'b'; |
| 147 | } | ||
| 148 | 145 | ||
| 149 | return env->make_string (env, buf, size-1); | 146 | return env->make_string (env, buf, size - 1); |
| 150 | } | 147 | } |
| 151 | 148 | ||
| 152 | 149 | ||
| 153 | /* | 150 | /* Embedded pointers in lisp objects. */ |
| 154 | * Embedded pointers in lisp objects. | ||
| 155 | */ | ||
| 156 | 151 | ||
| 157 | /* C struct (pointer to) that will be embedded */ | 152 | /* C struct (pointer to) that will be embedded. */ |
| 158 | struct super_struct | 153 | struct super_struct |
| 159 | { | 154 | { |
| 160 | int amazing_int; | 155 | int amazing_int; |
| 161 | char large_unused_buffer[512]; | 156 | char large_unused_buffer[512]; |
| 162 | }; | 157 | }; |
| 163 | 158 | ||
| 164 | /* Associated finalizer */ | 159 | /* Associated finalizer. */ |
| 165 | static void finalizer (void *p) | 160 | static void |
| 161 | finalizer (void *p) | ||
| 166 | { | 162 | { |
| 167 | if (p) | 163 | if (p) |
| 168 | free (p); | 164 | free (p); |
| 169 | } | 165 | } |
| 170 | 166 | ||
| 171 | /* | 167 | /* Return a new user-pointer to a super_struct, with amazing_int set |
| 172 | * Return a new user-pointer to a super_struct, with amazing_int set | 168 | to the passed parameter. */ |
| 173 | * to the passed parameter. | 169 | static emacs_value |
| 174 | */ | 170 | Fmod_test_userptr_make (emacs_env *env, int nargs, emacs_value args[], |
| 175 | static emacs_value Fmod_test_userptr_make (emacs_env *env, int nargs, emacs_value args[], void *data) | 171 | void *data) |
| 176 | { | 172 | { |
| 177 | struct super_struct *p = calloc (1, sizeof(*p)); | 173 | struct super_struct *p = calloc (1, sizeof *p); |
| 178 | p->amazing_int = env->extract_integer (env, args[0]); | 174 | p->amazing_int = env->extract_integer (env, args[0]); |
| 179 | return env->make_user_ptr (env, finalizer, p); | 175 | return env->make_user_ptr (env, free, p); |
| 180 | } | 176 | } |
| 181 | 177 | ||
| 182 | /* | 178 | /* Return the amazing_int of a passed 'user-pointer to a super_struct'. */ |
| 183 | * Return the amazing_int of a passed 'user-pointer to a super_struct'. | 179 | static emacs_value |
| 184 | */ | 180 | Fmod_test_userptr_get (emacs_env *env, int nargs, emacs_value args[], void *data) |
| 185 | static emacs_value Fmod_test_userptr_get (emacs_env *env, int nargs, emacs_value args[], void *data) | ||
| 186 | { | 181 | { |
| 187 | struct super_struct *p = env->get_user_ptr (env, args[0]); | 182 | struct super_struct *p = env->get_user_ptr (env, args[0]); |
| 188 | return env->make_integer (env, p->amazing_int); | 183 | return env->make_integer (env, p->amazing_int); |
| 189 | } | 184 | } |
| 190 | 185 | ||
| 191 | 186 | ||
| 192 | /* | 187 | /* Fill vector in args[0] with value in args[1]. */ |
| 193 | * Fill vector in args[0] with value in args[1] | 188 | static emacs_value |
| 194 | */ | 189 | Fmod_test_vector_fill (emacs_env *env, int nargs, emacs_value args[], void *data) |
| 195 | static emacs_value Fmod_test_vector_fill (emacs_env *env, int nargs, emacs_value args[], void *data) | ||
| 196 | { | 190 | { |
| 197 | size_t i; | ||
| 198 | emacs_value vec = args[0]; | 191 | emacs_value vec = args[0]; |
| 199 | emacs_value val = args[1]; | 192 | emacs_value val = args[1]; |
| 200 | const size_t size = env->vec_size (env, vec); | 193 | const size_t size = env->vec_size (env, vec); |
| 201 | for (i = 0; i < size; i++) | 194 | for (size_t i = 0; i < size; i++) |
| 202 | env->vec_set (env, vec, i, val); | 195 | env->vec_set (env, vec, i, val); |
| 203 | return env->intern (env, "t"); | 196 | return env->intern (env, "t"); |
| 204 | } | 197 | } |
| 205 | 198 | ||
| 206 | 199 | ||
| 207 | /* | 200 | /* Return whether all elements of vector in args[0] are 'eq' to value |
| 208 | * Return whether all elements of vector in args[0] are 'eq' to value in args[1] | 201 | in args[1]. */ |
| 209 | */ | 202 | static emacs_value |
| 210 | static emacs_value Fmod_test_vector_eq (emacs_env *env, int nargs, emacs_value args[], void *data) | 203 | Fmod_test_vector_eq (emacs_env *env, int nargs, emacs_value args[], void *data) |
| 211 | { | 204 | { |
| 212 | size_t i; | ||
| 213 | emacs_value vec = args[0]; | 205 | emacs_value vec = args[0]; |
| 214 | emacs_value val = args[1]; | 206 | emacs_value val = args[1]; |
| 215 | const size_t size = env->vec_size (env, vec); | 207 | const size_t size = env->vec_size (env, vec); |
| 216 | for (i = 0; i < size; i++) | 208 | for (size_t i = 0; i < size; i++) |
| 217 | if (!env->eq (env, env->vec_get (env, vec, i), val)) | 209 | if (!env->eq (env, env->vec_get (env, vec, i), val)) |
| 218 | return env->intern (env, "nil"); | 210 | return env->intern (env, "nil"); |
| 219 | return env->intern (env, "t"); | 211 | return env->intern (env, "t"); |
| 220 | } | 212 | } |
| 221 | 213 | ||
| 222 | 214 | ||
| 223 | /* | 215 | /* Lisp utilities for easier readability (simple wrappers). */ |
| 224 | * Lisp utilities for easier readability (simple wrappers) | ||
| 225 | */ | ||
| 226 | 216 | ||
| 227 | /* Provide FEATURE to Emacs */ | 217 | /* Provide FEATURE to Emacs. */ |
| 228 | static void provide (emacs_env *env, const char *feature) | 218 | static void |
| 219 | provide (emacs_env *env, const char *feature) | ||
| 229 | { | 220 | { |
| 230 | emacs_value Qfeat = env->intern (env, feature); | 221 | emacs_value Qfeat = env->intern (env, feature); |
| 231 | emacs_value Qprovide = env->intern (env, "provide"); | 222 | emacs_value Qprovide = env->intern (env, "provide"); |
| @@ -234,8 +225,9 @@ static void provide (emacs_env *env, const char *feature) | |||
| 234 | env->funcall (env, Qprovide, 1, args); | 225 | env->funcall (env, Qprovide, 1, args); |
| 235 | } | 226 | } |
| 236 | 227 | ||
| 237 | /* Binds NAME to FUN */ | 228 | /* Bind NAME to FUN. */ |
| 238 | static void bind_function (emacs_env *env, const char *name, emacs_value Sfun) | 229 | static void |
| 230 | bind_function (emacs_env *env, const char *name, emacs_value Sfun) | ||
| 239 | { | 231 | { |
| 240 | emacs_value Qfset = env->intern (env, "fset"); | 232 | emacs_value Qfset = env->intern (env, "fset"); |
| 241 | emacs_value Qsym = env->intern (env, name); | 233 | emacs_value Qsym = env->intern (env, name); |
| @@ -244,21 +236,22 @@ static void bind_function (emacs_env *env, const char *name, emacs_value Sfun) | |||
| 244 | env->funcall (env, Qfset, 2, args); | 236 | env->funcall (env, Qfset, 2, args); |
| 245 | } | 237 | } |
| 246 | 238 | ||
| 247 | /* | 239 | /* Module init function. */ |
| 248 | * Module init function. | 240 | int |
| 249 | */ | 241 | emacs_module_init (struct emacs_runtime *ert) |
| 250 | int emacs_module_init (struct emacs_runtime *ert) | ||
| 251 | { | 242 | { |
| 252 | emacs_env *env = ert->get_environment (ert); | 243 | emacs_env *env = ert->get_environment (ert); |
| 253 | 244 | ||
| 254 | #define DEFUN(lsym, csym, amin, amax, doc, data) \ | 245 | #define DEFUN(lsym, csym, amin, amax, doc, data) \ |
| 255 | bind_function (env, lsym, env->make_function (env, amin, amax, csym, doc, data)) | 246 | bind_function (env, lsym, \ |
| 247 | env->make_function (env, amin, amax, csym, doc, data)) | ||
| 256 | 248 | ||
| 257 | DEFUN ("mod-test-return-t", Fmod_test_return_t, 1, 1, NULL, NULL); | 249 | DEFUN ("mod-test-return-t", Fmod_test_return_t, 1, 1, NULL, NULL); |
| 258 | DEFUN ("mod-test-sum", Fmod_test_sum, 2, 2, "Return A + B", NULL); | 250 | DEFUN ("mod-test-sum", Fmod_test_sum, 2, 2, "Return A + B", NULL); |
| 259 | DEFUN ("mod-test-signal", Fmod_test_signal, 0, 0, NULL, NULL); | 251 | DEFUN ("mod-test-signal", Fmod_test_signal, 0, 0, NULL, NULL); |
| 260 | DEFUN ("mod-test-throw", Fmod_test_throw, 0, 0, NULL, NULL); | 252 | DEFUN ("mod-test-throw", Fmod_test_throw, 0, 0, NULL, NULL); |
| 261 | DEFUN ("mod-test-non-local-exit-funcall", Fmod_test_non_local_exit_funcall, 1, 1, NULL, NULL); | 253 | DEFUN ("mod-test-non-local-exit-funcall", Fmod_test_non_local_exit_funcall, |
| 254 | 1, 1, NULL, NULL); | ||
| 262 | DEFUN ("mod-test-globref-make", Fmod_test_globref_make, 0, 0, NULL, NULL); | 255 | DEFUN ("mod-test-globref-make", Fmod_test_globref_make, 0, 0, NULL, NULL); |
| 263 | DEFUN ("mod-test-string-a-to-b", Fmod_test_string_a_to_b, 1, 1, NULL, NULL); | 256 | DEFUN ("mod-test-string-a-to-b", Fmod_test_string_a_to_b, 1, 1, NULL, NULL); |
| 264 | DEFUN ("mod-test-userptr-make", Fmod_test_userptr_make, 1, 1, NULL, NULL); | 257 | DEFUN ("mod-test-userptr-make", Fmod_test_userptr_make, 1, 1, NULL, NULL); |
diff --git a/modules/mod-test/test.el b/modules/mod-test/test.el index ed584ebb95e..98ce46411bd 100644 --- a/modules/mod-test/test.el +++ b/modules/mod-test/test.el | |||
| @@ -19,11 +19,12 @@ | |||
| 19 | 19 | ||
| 20 | (require 'ert) | 20 | (require 'ert) |
| 21 | 21 | ||
| 22 | (add-to-list 'load-path (file-name-directory (or #$ (expand-file-name (buffer-file-name))))) | 22 | (add-to-list 'load-path |
| 23 | (file-name-directory (or #$ (expand-file-name (buffer-file-name))))) | ||
| 23 | (require 'mod-test) | 24 | (require 'mod-test) |
| 24 | 25 | ||
| 25 | ;; | 26 | ;; |
| 26 | ;; basic tests | 27 | ;; Basic tests. |
| 27 | ;; | 28 | ;; |
| 28 | 29 | ||
| 29 | (ert-deftest mod-test-sum-test () | 30 | (ert-deftest mod-test-sum-test () |
| @@ -33,7 +34,7 @@ | |||
| 33 | (should (string= (documentation 'mod-test-sum) "Return A + B"))) | 34 | (should (string= (documentation 'mod-test-sum) "Return A + B"))) |
| 34 | 35 | ||
| 35 | ;; | 36 | ;; |
| 36 | ;; non-local exists (throw, signal) | 37 | ;; Non-local exists (throw, signal). |
| 37 | ;; | 38 | ;; |
| 38 | 39 | ||
| 39 | (ert-deftest mod-test-non-local-exit-signal-test () | 40 | (ert-deftest mod-test-non-local-exit-signal-test () |
| @@ -51,7 +52,8 @@ | |||
| 51 | 23))) | 52 | 23))) |
| 52 | 53 | ||
| 53 | (ert-deftest mod-test-non-local-exit-funcall-signal () | 54 | (ert-deftest mod-test-non-local-exit-funcall-signal () |
| 54 | (should (equal (mod-test-non-local-exit-funcall (lambda () (signal 'error '(32)))) | 55 | (should (equal (mod-test-non-local-exit-funcall |
| 56 | (lambda () (signal 'error '(32)))) | ||
| 55 | '(signal error (32))))) | 57 | '(signal error (32))))) |
| 56 | 58 | ||
| 57 | (ert-deftest mod-test-non-local-exit-funcall-throw () | 59 | (ert-deftest mod-test-non-local-exit-funcall-throw () |
| @@ -59,7 +61,7 @@ | |||
| 59 | '(throw tag 32)))) | 61 | '(throw tag 32)))) |
| 60 | 62 | ||
| 61 | ;; | 63 | ;; |
| 62 | ;; string | 64 | ;; String tests. |
| 63 | ;; | 65 | ;; |
| 64 | 66 | ||
| 65 | (defun multiply-string (s n) | 67 | (defun multiply-string (s n) |
| @@ -77,7 +79,7 @@ | |||
| 77 | (should (string= (mod-test-string-a-to-b "aaa") "bbb"))) | 79 | (should (string= (mod-test-string-a-to-b "aaa") "bbb"))) |
| 78 | 80 | ||
| 79 | ;; | 81 | ;; |
| 80 | ;; user-pointer | 82 | ;; User-pointer tests. |
| 81 | ;; | 83 | ;; |
| 82 | 84 | ||
| 83 | (ert-deftest mod-test-userptr-fun-test () | 85 | (ert-deftest mod-test-userptr-fun-test () |
| @@ -92,7 +94,7 @@ | |||
| 92 | ;; TODO: try to test finalizer | 94 | ;; TODO: try to test finalizer |
| 93 | 95 | ||
| 94 | ;; | 96 | ;; |
| 95 | ;; vectors | 97 | ;; Vector tests. |
| 96 | ;; | 98 | ;; |
| 97 | 99 | ||
| 98 | (ert-deftest mod-test-vector-test () | 100 | (ert-deftest mod-test-vector-test () |
diff --git a/modules/modhelp.py b/modules/modhelp.py index 5afe8f24e95..45b849ee747 100755 --- a/modules/modhelp.py +++ b/modules/modhelp.py | |||
| @@ -56,7 +56,8 @@ def cmd_test(args): | |||
| 56 | print '[*] %s: running test' % m | 56 | print '[*] %s: running test' % m |
| 57 | testpath = os.path.join(m, 'test.el') | 57 | testpath = os.path.join(m, 'test.el') |
| 58 | if os.path.isfile(testpath): | 58 | if os.path.isfile(testpath): |
| 59 | emacs_cmd = [EMACS, '-batch', '-L', '.', '-l', 'ert', '-l', testpath, '-f', 'ert-run-tests-batch-and-exit'] | 59 | emacs_cmd = [EMACS, '-batch', '-L', '.', '-l', 'ert', |
| 60 | '-l', testpath, '-f', 'ert-run-tests-batch-and-exit'] | ||
| 60 | print ' '.join(emacs_cmd) | 61 | print ' '.join(emacs_cmd) |
| 61 | r = sp.call(emacs_cmd) | 62 | r = sp.call(emacs_cmd) |
| 62 | if r != 0: | 63 | if r != 0: |
| @@ -111,13 +112,16 @@ def main(): | |||
| 111 | subp = mainp.add_subparsers() | 112 | subp = mainp.add_subparsers() |
| 112 | 113 | ||
| 113 | testp = subp.add_parser('test', help='run tests') | 114 | testp = subp.add_parser('test', help='run tests') |
| 114 | testp.add_argument('-f', '--force', action='store_true', help='force regeneration (make -B)') | 115 | testp.add_argument('-f', '--force', action='store_true', |
| 115 | testp.add_argument('module', nargs='*', help='path to module to test (default all)') | 116 | help='force regeneration (make -B)') |
| 117 | testp.add_argument('module', nargs='*', | ||
| 118 | help='path to module to test (default all)') | ||
| 116 | testp.set_defaults(func=cmd_test) | 119 | testp.set_defaults(func=cmd_test) |
| 117 | 120 | ||
| 118 | initp = subp.add_parser('init', help='create a test module from a template') | 121 | initp = subp.add_parser('init', help='create a test module from a template') |
| 119 | initp.add_argument('module', help='name of the new module') | 122 | initp.add_argument('module', help='name of the new module') |
| 120 | initp.add_argument('-f', '--fun', default='fun', help='overide name of the default function') | 123 | initp.add_argument('-f', '--fun', default='fun', |
| 124 | help='overide name of the default function') | ||
| 121 | initp.set_defaults(func=cmd_init) | 125 | initp.set_defaults(func=cmd_init) |
| 122 | 126 | ||
| 123 | args = mainp.parse_args() | 127 | args = mainp.parse_args() |
| @@ -149,13 +153,15 @@ all: ${module}.so ${module}.doc | |||
| 149 | 153 | ||
| 150 | int plugin_is_GPL_compatible; | 154 | int plugin_is_GPL_compatible; |
| 151 | 155 | ||
| 152 | static emacs_value ${c_func} (emacs_env *env, int nargs, emacs_value args[], void *data) | 156 | static emacs_value |
| 157 | ${c_func} (emacs_env *env, int nargs, emacs_value args[], void *data) | ||
| 153 | { | 158 | { |
| 154 | return env->intern (env, "t"); | 159 | return env->intern (env, "t"); |
| 155 | } | 160 | } |
| 156 | 161 | ||
| 157 | /* Binds NAME to FUN */ | 162 | /* Bind NAME to FUN. */ |
| 158 | static void bind_function (emacs_env *env, const char *name, emacs_value Sfun) | 163 | static void |
| 164 | bind_function (emacs_env *env, const char *name, emacs_value Sfun) | ||
| 159 | { | 165 | { |
| 160 | emacs_value Qfset = env->intern (env, "fset"); | 166 | emacs_value Qfset = env->intern (env, "fset"); |
| 161 | emacs_value Qsym = env->intern (env, name); | 167 | emacs_value Qsym = env->intern (env, name); |
| @@ -164,8 +170,9 @@ static void bind_function (emacs_env *env, const char *name, emacs_value Sfun) | |||
| 164 | env->funcall (env, Qfset, 2, args); | 170 | env->funcall (env, Qfset, 2, args); |
| 165 | } | 171 | } |
| 166 | 172 | ||
| 167 | /* Provide FEATURE to Emacs */ | 173 | /* Provide FEATURE to Emacs. */ |
| 168 | static void provide (emacs_env *env, const char *feature) | 174 | static void |
| 175 | provide (emacs_env *env, const char *feature) | ||
| 169 | { | 176 | { |
| 170 | emacs_value Qfeat = env->intern (env, feature); | 177 | emacs_value Qfeat = env->intern (env, feature); |
| 171 | emacs_value Qprovide = env->intern (env, "provide"); | 178 | emacs_value Qprovide = env->intern (env, "provide"); |
| @@ -174,10 +181,12 @@ static void provide (emacs_env *env, const char *feature) | |||
| 174 | env->funcall (env, Qprovide, 1, args); | 181 | env->funcall (env, Qprovide, 1, args); |
| 175 | } | 182 | } |
| 176 | 183 | ||
| 177 | int emacs_module_init (struct emacs_runtime *ert) | 184 | int |
| 185 | emacs_module_init (struct emacs_runtime *ert) | ||
| 178 | { | 186 | { |
| 179 | emacs_env *env = ert->get_environment (ert); | 187 | emacs_env *env = ert->get_environment (ert); |
| 180 | bind_function (env, "${lisp_func}", env->make_function (env, 1, 1, ${c_func}, "doc", NULL)); | 188 | bind_function (env, "${lisp_func}", |
| 189 | env->make_function (env, 1, 1, ${c_func}, "doc", NULL)); | ||
| 181 | provide (env, "${module}"); | 190 | provide (env, "${module}"); |
| 182 | return 0; | 191 | return 0; |
| 183 | } | 192 | } |