49
49
char *search_path[2];
50
const char *test_filename = test_data;
51
const char *js_version;
53
js_version = gjs_context_scan_file_for_js_version(test_filename);
51
55
search_path[0] = g_build_filename(top_srcdir, "test", "modules", NULL);
52
56
search_path[1] = NULL;
54
fix->context = gjs_context_new_with_search_path(search_path);
58
fix->context = g_object_new (GJS_TYPE_CONTEXT,
59
"search-path", search_path,
60
"js-version", js_version,
55
62
g_free(search_path[0]);
57
64
/* Load jsUnit.js directly into global scope, rather than
121
/* Always return an absolute filename and treat all absolute path elements as
122
* absolute, not just the first one, e.g.
123
* ("/foo", "/bar", NULL) returns "/bar"
124
* (g_build_filename would return "/foo/bar")
125
* Returned path may still include '..' path elements.
128
build_absolute_filename(const char *first_element,
137
cwd = g_get_current_dir();
139
array = g_ptr_array_new();
141
g_ptr_array_add(array, cwd);
143
va_start(ap, first_element);
145
element = first_element;
146
while (element != NULL) {
147
if (g_path_is_absolute(element))
148
g_ptr_array_set_size(array, 0);
150
g_ptr_array_add(array, (char*)element);
152
element = va_arg(ap, const char *);
156
g_ptr_array_add(array, NULL);
158
path = g_build_filenamev((char **)array->pdata);
160
g_ptr_array_free(array, TRUE);
115
168
main(int argc, char **argv)
117
/* These are relative to top_builddir */
170
/* These may be absolute or relative to top_builddir, depending whether
171
* GJS_TOP_SRCDIR is absolute or not */
118
172
const char * const path_directories[] = {
119
173
GJS_TOP_SRCDIR"/modules",
120
174
GJS_TOP_SRCDIR"/test/js/modules",
135
189
working_dir = g_get_current_dir();
137
if(g_path_is_absolute(argv[0]))
138
gjs_unit_path = g_strdup(argv[0]);
140
gjs_unit_path = g_build_filename(working_dir, argv[0], NULL);
191
gjs_unit_path = build_absolute_filename(argv[0], NULL);
142
193
gjs_unit_dir = g_path_get_dirname(gjs_unit_path);
143
194
/* the gjs-unit executable will be in <top_builddir>/.libs */
144
top_builddir = g_build_filename(gjs_unit_dir, "..", NULL);
145
top_srcdir = g_build_filename(top_builddir, GJS_TOP_SRCDIR, NULL);
195
top_builddir = g_path_get_dirname(gjs_unit_dir);
196
top_srcdir = build_absolute_filename(top_builddir, GJS_TOP_SRCDIR, NULL);
147
198
/* Normalize, not strictly necessary */
148
199
g_chdir(top_builddir);
167
218
g_string_append_c(path, ':');
169
directory = g_build_filename(top_builddir, path_directories[i], NULL);
220
directory = build_absolute_filename(top_builddir, path_directories[i], NULL);
170
221
g_string_append(path, directory);
171
222
g_free(directory);