instead of statics. Then maybe times_up() can use pane_too_long()
- [X] mark DEF_CMD structs as const- NO, ->refcnt is not constant.
- [X] rexel: don't abort if something looks wrong, just fail.
+- [X] check EDLIB_TESTING just once and set a flag in editor, accessible
+ as pane_testing(): p->root->data(cast)->testing.
### Small
struct mark *mark_free_list;
struct map *map safe;
struct lookup_cmd cmd;
+ bool testing;
struct store {
struct store *next;
int size;
} *store;
};
+bool edlib_testing(struct pane *p safe)
+{
+ struct ed_info *ei = pane_root(p)->data;
+ return ei->testing;
+}
+
DEF_LOOKUP_CMD(ed_handle, ed_map);
DEF_CMD(global_set_attr)
alloc(ei, pane);
ei->magic = ED_MAGIC;
+ ei->testing = (getenv("EDLIB_TESTING") != NULL);
if (! (void*) ed_map) {
ed_map = key_alloc();
key_add(ed_map, "global-set-attr", &global_set_attr);
*/
unsigned int timestamp;
- struct pane *root;
+ struct pane *root safe;
struct command *handle;
void *data safe;
struct attrset *attrs;
char *strnsave(struct pane *p safe, const char *buf, int len);
char * safe __strconcat(struct pane *p, const char *s1 safe, ...);
#define strconcat(p, ...) __strconcat(p, __VA_ARGS__, NULL)
+bool edlib_testing(struct pane *p safe);
/* This is declared here so sparse knows it is global */
void edlib_init(struct pane *ed safe);
return de->nbuf;
}
-static char *fmt_date(struct dir_ent *de safe, time_t t)
+static char *fmt_date(struct dir_ent *de safe, time_t t, struct pane *p safe)
{
struct tm tm;
time_t now = time(NULL);
- char *testing = getenv("EDLIB_TESTING");
- if (testing && *testing) {
+ if (edlib_testing(p)) {
t = 1581382278;
now = t;
}
} else if (strcmp(attr, "hsize") == 0) {
get_stat(dr, de);
if (strchr(".:d", de->ch) &&
- getenv("EDLIB_TESTING"))
+ edlib_testing(home))
/* Size might not be reliable for testing */
return "DIR";
return fmt_size(de, de->st.st_size);
return fmt_num(de, de->st.st_mtime);
} else if (strcmp(attr, "mdate") == 0) {
get_stat(dr, de);
- return fmt_date(de, de->st.st_mtime);
+ return fmt_date(de, de->st.st_mtime, home);
} else if (strcmp(attr, "atime") == 0) {
get_stat(dr, de);
return fmt_num(de, de->st.st_atime);
} else if (strcmp(attr, "adate") == 0) {
get_stat(dr, de);
- return fmt_date(de, de->st.st_atime);
+ return fmt_date(de, de->st.st_atime, home);
} else if (strcmp(attr, "ctime") == 0) {
get_stat(dr, de);
return fmt_num(de, de->st.st_ctime);
} else if (strcmp(attr, "cdate") == 0) {
get_stat(dr, de);
- return fmt_date(de, de->st.st_ctime);
+ return fmt_date(de, de->st.st_ctime, home);
} else if (strcmp(attr, "uid") == 0) {
get_stat(dr, de);
return fmt_num(de, de->st.st_uid);
} else if (strcmp(attr, "user") == 0) {
char *n;
get_stat(dr, de);
- if (getenv("EDLIB_TESTING"))
+ if (edlib_testing(home))
return "User";
n = pwname(de->st.st_uid);
if (n)
} else if (strcmp(attr, "group") == 0) {
char *n;
get_stat(dr, de);
- if (getenv("EDLIB_TESTING"))
+ if (edlib_testing(home))
return "Group";
n = grname(de->st.st_gid);
if (n)
case S_IFLNK: *c ++ = 'l'; break;
default: *c ++ = '?'; break;
}
- if (getenv("EDLIB_TESTING") && de->ch == ':')
+ if (edlib_testing(home) && de->ch == ':')
/* ".." might not be under control of the test */
mode = 0777;
for (i = 0; i < 3; i++) {
{
call_comm("event:free", p, &emacs_search_reposition_delayed);
call_comm("event:timer", p, &emacs_search_reposition_delayed,
- getenv("EDLIB_TESTING") ? 50 : 500);
+ edlib_testing(p) ? 50 : 500);
}
DEF_CMD(emacs_search_reposition)
PyModule_AddIntConstant(m, "WEOF", 0x3FFFFF);
+ PyModule_AddIntConstant(m, "testing", edlib_testing(ed));
+
Edlib_CommandFailed = PyErr_NewException("edlib.commandfailed", NULL, NULL);
Py_INCREF(Edlib_CommandFailed);
PyModule_AddObject(m, "commandfailed", Edlib_CommandFailed);
struct trigger *t = cd->last_trigger;
if (strstarts(name, "TESTING ")) {
- if (getenv("EDLIB_TESTING") == NULL)
+ if (!edlib_testing(cd->root))
return;
name += 8;
}
if (strstarts(name, "NOTESTING ")) {
- if (getenv("EDLIB_TESTING") != NULL)
+ if (edlib_testing(cd->root))
return;
name += 10;
}
DEF_LOOKUP_CMD(handle_count_lines, linecount_map);
static const int batch_marks = 10;
-static bool testing = False;
struct count_info {
int view_num;
struct mark *m, *m2;
char *disable;
- if (testing)
+ if (edlib_testing(p))
sync = True;
disable = pane_attr_get(p, "linecount-disable");
attr_set_int(&p->attrs, "lines", lines);
attr_set_int(&p->attrs, "words", words);
attr_set_int(&p->attrs, "chars", chars);
- if (!testing)
+ if (!edlib_testing(p))
pane_notify("doc:status-changed", p);
}
}
call_comm("global-set-command", ed, &count_lines, 0, NULL, "CountLines");
call_comm("global-set-command", ed, &count_lines, 0, NULL, "CountLinesAsync");
- if (getenv("EDLIB_TESTING"))
- testing = True;
-
if (linecount_map)
return;
struct mlinfo *mli = ci->home->data;
int wait_time = 7;
- if (getenv("EDLIB_TESTING"))
+ if (edlib_testing(ci->home))
wait_time = 0;
if (mli->modal) {
char buf[80];
time_t t;
struct tm *tm;
- char *testing = getenv("EDLIB_TESTING");
+
t = time(NULL);
- if (testing && *testing)
+ if (edlib_testing(ci->home))
t = 1581382278;
tm = localtime(&t);
if (tm)
}
mli->line = mlp;
pane_focus(ret);
- if (getenv("EDLIB_TESTING") == NULL)
+ if (!edlib_testing(p))
/* This can introduce unwanted variablitiy in tests */
call_comm("event:timer", mli->line, &force_refresh, 15000);
self.set_time()
focus = focus.leaf
- if 'EDLIB_TESTING' in os.environ:
+ if edlib.testing:
remain = 20
else:
remain = 200
self.ev_num = 0
self.dont_block = False
self.maxloops = 10
- if 'EDLIB_TESTING' in os.environ:
+ if edlib.testing:
self.maxloops = -1
def handle_close(self, key, focus, **a):
done = 0
self.set_time()
- testing = 'EDLIB_TESTING' in os.environ
- while testing or (done < 100 and not self.too_long()):
+ while edlib.testing or (done < 100 and not self.too_long()):
# Look for one of:
# filename:linenum:.....
# filename:linenum ....
self.call("doc:set:doc-status", "Running")
self.call("doc:notify:doc:status-changed")
fd = self.pipe.stdout.fileno()
- if 'EDLIB_TESTING' not in os.environ:
+ if not edlib.testing:
fl = fcntl.fcntl(fd, fcntl.F_GETFL)
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NONBLOCK)
self.call("event:read", fd, self.read)
if not self.pipe:
return edlib.Efalse
try:
- if 'EDLIB_TESTING' not in os.environ:
+ if not edlib.testing:
r = os.read(self.pipe.stdout.fileno(), 4096)
else:
r = b''