[augeas-devel] [PATCH] Add aug_span API function

Francis Giraldeau francis.giraldeau at gmail.com
Tue Jan 25 04:03:59 UTC 2011


aug_span API function provides information about the node of the specified tree
path. It sets the absolute path of the file name and indexes of label, value
and span inside the node. The span includes all matching chars of the actual
lens and it's descendant. Hence, the top level node will span the entire file.
It returns 0 in case of success and -1 if the node is not associated to a file
or if the path is invalid.  The main use case is to make possible to display
the related file with the node elements hightlighted in a UI.

The API option AUG_NO_NODE_INDEX provided to aug_init disable the allocation of
structures to keep node indexes. It saves about 5% of memory for a typical
tree.

  * src/augeas.c : add aug_span implementation and option handling to aug_init
    according to the option /augeas/indez in the tree
  * src/augeas.h : add declaration of aug_span and constants for option
  * src/augeas_sym.version : make the new function visible in libaugeas
  * src/augtool.c : add the "nodepos" command to augtool
  * src/get.c : gather filename, label, value and span indexes if any
  * src/info.c : create and release functions for struct node_span
  * src/info.h : add definition of struct node_info
  * src/internal.h : add node_info to struct tree
  * src/transform.c : duplicate filename string
  * tests/test-load.c : 3 basic unit tests for general correct behavior

Recursive lens and regular lens are supported.
---
 .gnulib                |    2 +-
 src/augeas.c           |   66 ++++++++++++++++++++++++++++++++++++
 src/augeas.h           |   20 ++++++++++-
 src/augeas_sym.version |    5 +++
 src/augtool.c          |   56 ++++++++++++++++++++++++++++++-
 src/get.c              |   37 +++++++++++++++++++-
 src/info.c             |   40 ++++++++++++++++++++++
 src/info.h             |   17 +++++++++
 src/internal.h         |    9 +++++
 src/transform.c        |    4 +-
 tests/cutest.h         |    4 ++
 tests/test-api.c       |   86 ++++++++++++++++++++++++++++++++++++++++++++++++
 tests/test-load.c      |    5 ---
 13 files changed, 339 insertions(+), 12 deletions(-)

diff --git a/.gnulib b/.gnulib
index e240ab4..e764ea2 160000
--- a/.gnulib
+++ b/.gnulib
@@ -1 +1 @@
-Subproject commit e240ab433593692f27c804c26ec1730a0dd27e5d
+Subproject commit e764ea2fcb9a6247ae4dc0d4c0566b43d950a694
diff --git a/src/augeas.c b/src/augeas.c
index 25ca016..3391530 100644
--- a/src/augeas.c
+++ b/src/augeas.c
@@ -421,6 +421,13 @@ struct augeas *aug_init(const char *root, const char *loadpath,
     } else {
         aug_set(result, AUGEAS_META_SAVE_MODE, AUG_SAVE_OVERWRITE_TEXT);
     }
+
+    if (flags & AUG_NO_NODE_INDEX) {
+        aug_set(result, AUGEAS_INDEX_OPTION, AUG_DISABLE);
+    } else {
+        aug_set(result, AUGEAS_INDEX_OPTION, AUG_ENABLE);
+    }
+
     /* Make sure we always have /files and /augeas/variables */
     tree_path_cr(result->origin, 1, s_files);
     tree_path_cr(result->origin, 2, s_augeas, s_vars);
@@ -503,6 +510,7 @@ static void tree_rm_dirty_leaves(struct augeas *aug, struct tree *tree,
 }
 
 int aug_load(struct augeas *aug) {
+    const char *option = NULL;
     struct tree *meta = tree_child_cr(aug->origin, s_augeas);
     struct tree *meta_files = tree_child_cr(meta, s_files);
     struct tree *files = tree_child_cr(aug->origin, s_files);
@@ -527,6 +535,16 @@ int aug_load(struct augeas *aug) {
      * (4) Remove entries from /augeas/files and /files that correspond
      *     to directories without any files of interest
      */
+
+    /* update flags according to option value */
+    if (aug_get(aug, AUGEAS_INDEX_OPTION, &option) == 1) {
+        if (strcmp(option, AUG_ENABLE) == 0) {
+            aug->flags &= ~AUG_NO_NODE_INDEX;
+        } else if (strcmp(option, AUG_DISABLE) == 0) {
+            aug->flags |= AUG_NO_NODE_INDEX;
+        }
+    }
+
     tree_clean(meta_files);
     tree_mark_files(meta_files);
 
@@ -841,6 +859,8 @@ struct tree *make_tree(char *label, char *value, struct tree *parent,
         tree_mark_dirty(tree);
     else
         tree->dirty = 1;
+    // FIXME: should allocation belong to make_tree?
+    //tree->node_info = make_node_info();
     return tree;
 }
 
@@ -860,6 +880,7 @@ static void free_tree_node(struct tree *tree) {
     if (tree == NULL)
         return;
 
+    unref(tree->node_info, node_info);
     free(tree->label);
     free(tree->value);
     free(tree);
@@ -943,6 +964,51 @@ int aug_rm(struct augeas *aug, const char *path) {
     return -1;
 }
 
+int aug_span(struct augeas *aug, const char *path, char **filename,
+        uint *label_start, uint *label_end, uint *value_start, uint *value_end,
+        uint *span_start, uint *span_end) {
+    struct pathx *p = NULL;
+    int result;
+    struct tree *tree = NULL;
+
+    api_entry(aug);
+    p = pathx_aug_parse(aug, aug->origin, path, true);
+    tree = pathx_first(p);
+    if (tree == NULL || tree->node_info == NULL){
+        result = -1;
+        goto error;
+    }
+
+    if (label_start != NULL)
+        *label_start = tree->node_info->label_start;
+    if (label_end != NULL)
+        *label_end   = tree->node_info->label_end;
+    if (value_start != NULL)
+        *value_start = tree->node_info->value_start;
+    if (value_end != NULL)
+        *value_end   = tree->node_info->value_end;
+    if (span_start != NULL)
+        *span_start  = tree->node_info->span_start;
+    if (span_end != NULL)
+        *span_end    = tree->node_info->span_end;
+
+    /* We are safer here, make sure we have a filename */
+    if (tree->node_info->filename == NULL || tree->node_info->filename->str == NULL) {
+        *filename = strdup("");
+    } else {
+        *filename = strdup(tree->node_info->filename->str);
+    }
+
+    result = 0;
+    ERR_BAIL(aug);
+    api_exit(aug);
+    return result;
+
+ error:
+    api_exit(aug);
+    return result;
+}
+
 int tree_replace(struct augeas *aug, const char *path, struct tree *sub) {
     struct tree *parent;
     struct pathx *p = NULL;
diff --git a/src/augeas.h b/src/augeas.h
index b4848cb..18beaba 100644
--- a/src/augeas.h
+++ b/src/augeas.h
@@ -47,7 +47,8 @@ enum aug_flags {
     AUG_SAVE_NOOP    = (1 << 4),  /* Make save a no-op process, just record
                                      what would have changed */
     AUG_NO_LOAD      = (1 << 5),  /* Do not load the tree from AUG_INIT */
-    AUG_NO_MODL_AUTOLOAD = (1 << 6)
+    AUG_NO_MODL_AUTOLOAD = (1 << 6),
+    AUG_NO_NODE_INDEX    = (1 << 7) /* Do not keep track of node indexes */
 };
 
 /* Function: aug_init
@@ -149,6 +150,23 @@ int aug_set(augeas *aug, const char *path, const char *value);
  */
 int aug_setm(augeas *aug, const char *base, const char *sub, const char *value);
 
+/* Function: aug_span
+ *
+ * Get the information about the node associated with PATH. If the node is
+ * associated with a file, the filename, label and value start and end positions
+ * are set, and return value is 0. If the node associated with PATH doesn't
+ * belong to a file or is doesn't exists, filename and indexes are not set and
+ * return value is -1.
+ *
+ * Returns:
+ * 0 on success with filename, label_start, label_stop, value_start, value_end
+ * -1 on error
+ */
+
+int aug_span(augeas *aug, const char *path, char **filename,
+        uint *label_start, uint *label_end, uint *value_start, uint *value_end,
+        uint *span_start, uint *span_end);
+
 /* Function: aug_insert
  *
  * Create a new sibling LABEL for PATH by inserting into the tree just
diff --git a/src/augeas_sym.version b/src/augeas_sym.version
index 542f5fa..3f065f1 100644
--- a/src/augeas_sym.version
+++ b/src/augeas_sym.version
@@ -34,3 +34,8 @@ AUGEAS_0.11.0 {
     global:
       aug_setm;
 } AUGEAS_0.10.0;
+
+AUGEAS_0.12.0 {
+    global:
+      aug_span;
+} AUGEAS_0.11.0;
diff --git a/src/augtool.c b/src/augtool.c
index 7de8e9d..6208162 100644
--- a/src/augtool.c
+++ b/src/augtool.c
@@ -661,6 +661,54 @@ static const struct command_def cmd_clearm_def = {
     "BASE will be modified."
 };
 
+static void cmd_span(struct command *cmd) {
+    const char *path = arg_value(cmd, "path");
+    int r;
+    uint label_start, label_end, value_start, value_end, span_start, span_end;
+    char *filename;
+    const char *option;
+    // FIXME: add check to see if AUG_NO_NODE_INDEX is set
+
+    if (aug_get(aug, AUGEAS_INDEX_OPTION, &option) != 1) {
+        printf("Error: option /augeas/index not found\n");
+        return;
+    }
+    if (strcmp(AUG_DISABLE, option) == 0) {
+        printf("Indexes are not enabled. To enable, run commands:\n");
+        printf("set %s %s\n", AUGEAS_INDEX_OPTION, AUG_ENABLE);
+        printf("rm %s\n", AUGEAS_FILES_TREE);
+        printf("load\n");
+        return;
+    } else if (strcmp(AUG_ENABLE, option) != 0) {
+        printf("Error: option %s must be %s or %s\n", AUGEAS_INDEX_OPTION,
+               AUG_ENABLE, AUG_DISABLE);
+        return;
+    }
+    r = aug_span(aug, path, &filename, &label_start, &label_end, &value_start, 
+                 &value_end, &span_start, &span_end);
+    err_check(cmd);
+    if (r == -1){
+        printf ("Failed\n");
+        return;
+    }
+    printf("%s label=(%i:%i) value=(%i:%i) span=(%i,%i)\n", filename, 
+           label_start, label_end, value_start, value_end, span_start, span_end);
+}
+
+static const struct command_opt_def cmd_span_opts[] = {
+    { .type = CMD_PATH, .name = "path", .optional = false,
+      .help = "node path" },
+    CMD_OPT_DEF_LAST
+};
+
+static const struct command_def cmd_span_def = {
+    .name = "span",
+    .opts = cmd_span_opts,
+    .handler = cmd_span,
+    .synopsis = "get the filename, label and value position in the text of this node",
+    .help = "get the filename, label and value position in the text of this node"
+};
+
 static void cmd_defvar(struct command *cmd) {
     const char *name = arg_value(cmd, "name");
     const char *path = arg_value(cmd, "expr");
@@ -971,6 +1019,7 @@ static const struct command_def const *commands[] = {
     &cmd_set_def,
     &cmd_setm_def,
     &cmd_clearm_def,
+    &cmd_span_def,
     &cmd_help_def,
     &cmd_def_last
 };
@@ -1047,7 +1096,8 @@ static void parse_opts(int argc, char **argv) {
         VAL_NO_STDINC = CHAR_MAX + 1,
         VAL_NO_LOAD = VAL_NO_STDINC + 1,
         VAL_NO_AUTOLOAD = VAL_NO_LOAD + 1,
-        VAL_VERSION = VAL_NO_AUTOLOAD + 1
+        VAL_VERSION = VAL_NO_AUTOLOAD + 1,
+        VAL_NO_INDEX = VAL_VERSION + 1
     };
     struct option options[] = {
         { "help",      0, 0, 'h' },
@@ -1062,6 +1112,7 @@ static void parse_opts(int argc, char **argv) {
         { "nostdinc",  0, 0, VAL_NO_STDINC },
         { "noload",    0, 0, VAL_NO_LOAD },
         { "noautoload", 0, 0, VAL_NO_AUTOLOAD },
+        { "noindex", 0, 0, VAL_NO_INDEX },
         { "version",   0, 0, VAL_VERSION },
         { 0, 0, 0, 0}
     };
@@ -1109,6 +1160,9 @@ static void parse_opts(int argc, char **argv) {
             flags |= AUG_NO_MODL_AUTOLOAD;
             print_version = true;
             break;
+        case VAL_NO_INDEX:
+            flags |= AUG_NO_NODE_INDEX;
+            break;
         default:
             usage();
             break;
diff --git a/src/get.c b/src/get.c
index dbab6fa..6c178c9 100644
--- a/src/get.c
+++ b/src/get.c
@@ -45,6 +45,7 @@ struct seq {
 
 struct state {
     struct info      *info;
+    struct node_info *node_info;
     const char       *text;
     struct seq       *seqs;
     char             *key;
@@ -73,6 +74,7 @@ struct frame {
     struct lens     *lens;
     char            *key;
     char            *square;
+    struct node_info *node_info;
     union {
         struct { /* MGET */
             char        *value;
@@ -388,6 +390,7 @@ static struct tree *get_del(struct lens *lens, struct state *state) {
     if (lens->string == NULL) {
         state->square = token(state);
     }
+    update_span(state->node_info, REG_START(state), REG_END(state));
     return NULL;
 }
 
@@ -413,8 +416,14 @@ static struct tree *get_store(struct lens *lens, struct state *state) {
         get_error(state, lens, "More than one store in a subtree");
     else if (! REG_MATCHED(state))
         no_match_error(state, lens);
-    else
+    else {
         state->value = token(state);
+        if (state->node_info) {
+            state->node_info->value_start = REG_START(state);
+            state->node_info->value_end = REG_END(state);
+            update_span(state->node_info, REG_START(state), REG_END(state));
+        }
+    }
     return tree;
 }
 
@@ -440,8 +449,15 @@ static struct tree *get_key(struct lens *lens, struct state *state) {
     ensure0(lens->tag == L_KEY, state->info);
     if (! REG_MATCHED(state))
         no_match_error(state, lens);
-    else
+    else {
         state->key = token(state);
+        if (state->node_info) {
+            state->node_info->label_start = REG_START(state);
+            state->node_info->label_end = REG_END(state);
+            //printf("key=%s,key_start=%i,key_end=%i\n", state->key, state->key_start, state->key_end);
+            update_span(state->node_info, REG_START(state), REG_END(state));
+        }
+    }
     return NULL;
 }
 
@@ -661,16 +677,27 @@ static struct skel *parse_quant_maybe(struct lens *lens, struct state *state,
 static struct tree *get_subtree(struct lens *lens, struct state *state) {
     char *key = state->key;
     char *value = state->value;
+    struct node_info *node_info = state->node_info;
+
     struct tree *tree = NULL, *children;
 
     state->key = NULL;
     state->value = NULL;
+    if (!(state->info->flags & AUG_NO_NODE_INDEX))
+        state->node_info = make_node_info(state->info);
+
     children = get_lens(lens->child, state);
 
     tree = make_tree(state->key, state->value, NULL, children);
+    tree->node_info = state->node_info;
+
+    if (state->node_info != NULL) {
+        update_span(node_info, state->node_info->span_start, state->node_info->span_end);
+    }
 
     state->key = key;
     state->value = value;
+    state->node_info = node_info;
     return tree;
 }
 
@@ -855,8 +882,12 @@ static void visit_enter(struct lens *lens,
         struct frame *f = push_frame(rec_state, lens);
         f->key = state->key;
         f->value = state->value;
+        f->node_info = state->node_info;
         state->key = NULL;
         state->value = NULL;
+        if (!(state->info->flags & AUG_NO_NODE_INDEX)) {
+            state->node_info = make_node_info(state->info);
+        }
     }
 }
 
@@ -948,11 +979,13 @@ static void visit_exit(struct lens *lens,
             struct tree *tree;
             // FIXME: tree may leak if pop_frame ensure0 fail
             tree = make_tree(top->key, top->value, NULL, top->tree);
+            tree->node_info = state->node_info;
             ERR_NOMEM(tree == NULL, lens->info);
             top = pop_frame(rec_state);
             ensure(lens == top->lens, state->info);
             state->key = top->key;
             state->value = top->value;
+            state->node_info = top->node_info;
             pop_frame(rec_state);
             top = push_frame(rec_state, lens);
             top->tree = tree;
diff --git a/src/info.c b/src/info.c
index 9363477..8052026 100644
--- a/src/info.c
+++ b/src/info.c
@@ -113,6 +113,46 @@ void free_info(struct info *info) {
     free(info);
 }
 
+struct node_info *make_node_info(struct info *info) {
+    struct node_info *node_info = NULL;
+    if (make_ref(node_info) < 0) {
+        unref(node_info, node_info);
+    }
+    node_info->filename = ref(info->filename);
+    node_info->is_first_update = true;
+    return node_info;
+}
+
+void free_node_info(struct node_info *node_info) {
+    if (node_info == NULL)
+        return;
+    assert(node_info->ref == 0);
+    unref(node_info->filename, string);
+    free(node_info);
+}
+
+void print_node_info(struct node_info *n) {
+    if (n == NULL)
+        return;
+    printf("%s ifu=%i label=(%i:%i) value=(%i:%i) span=(%i,%i)\n", n->filename->str, n->is_first_update,
+           n->label_start, n->label_end, n->value_start, n->value_end, n->span_start, n->span_end);
+}
+
+void update_span(struct node_info *node_info, int x, int y) {
+    if (node_info == NULL)
+        return;
+    if (node_info->is_first_update) {
+        node_info->span_start = x;
+        node_info->span_end = y;
+        node_info->is_first_update = false;
+    } else {
+        if (node_info->span_start > x)
+            node_info->span_start = x;
+        if (node_info->span_end < y)
+            node_info->span_end = y;
+    }
+}
+
 /*
  * Local variables:
  *  indent-tabs-mode: nil
diff --git a/src/info.h b/src/info.h
index cc5d2ce..fe6a6bf 100644
--- a/src/info.h
+++ b/src/info.h
@@ -51,6 +51,19 @@ struct info {
     uint16_t last_line;
     uint16_t last_column;
     ref_t    ref;
+    int flags;
+};
+
+struct node_info {
+    struct string *filename;
+    uint label_start;
+    uint label_end;
+    uint value_start;
+    uint value_end;
+    uint span_start;
+    uint span_end;
+    char is_first_update;
+    ref_t ref;
 };
 
 char *format_info(struct info *info);
@@ -60,6 +73,10 @@ void print_info(FILE *out, struct info *info);
 /* Do not call directly, use UNREF instead */
 void free_info(struct info *info);
 
+struct node_info *make_node_info(struct info *info);
+void free_node_info(struct node_info *node_info);
+void update_span(struct node_info *node_info, int x, int y);
+void print_node_info(struct node_info *node_info);
 #endif
 
 
diff --git a/src/internal.h b/src/internal.h
index 71c5d42..57d39e8 100644
--- a/src/internal.h
+++ b/src/internal.h
@@ -90,6 +90,10 @@
 /* Where to put information about parsing of path expressions */
 #define AUGEAS_META_PATHX AUGEAS_META_TREE "/pathx"
 
+/* Define: AUGEAS_INDEX_OPTION
+ * Enable or disable node indexes */
+#define AUGEAS_INDEX_OPTION AUGEAS_META_TREE "/index"
+
 /* Define: AUGEAS_LENS_ENV
  * Name of env var that contains list of paths to search for additional
    spec files */
@@ -111,6 +115,10 @@
 #define AUG_SAVE_NOOP_TEXT "noop"
 #define AUG_SAVE_OVERWRITE_TEXT "overwrite"
 
+/* constants for options in the tree */
+#define AUG_ENABLE "enable"
+#define AUG_DISABLE "disable"
+
 #ifdef __GNUC__
 
 #ifndef __GNUC_PREREQ
@@ -344,6 +352,7 @@ struct tree {
     struct tree *children;   /* List of children through NEXT */
     char        *value;
     int          dirty;
+    struct node_info *node_info;
 };
 
 /* The opaque structure used to represent path expressions. API's
diff --git a/src/transform.c b/src/transform.c
index 521414b..e068e51 100644
--- a/src/transform.c
+++ b/src/transform.c
@@ -503,13 +503,13 @@ static int load_file(struct augeas *aug, struct lens *lens,
     struct info *info;
     make_ref(info);
     make_ref(info->filename);
-    info->filename->str = filename;
+    info->filename->str = strdup(filename);
     info->error = aug->error;
+    info->flags = aug->flags;
     info->first_line = 1;
 
     tree = lns_get(info, lens, text, &err);
 
-    info->filename->str = NULL;
     unref(info, info);
 
     if (err != NULL) {
diff --git a/tests/cutest.h b/tests/cutest.h
index 616fb1f..99e2d34 100644
--- a/tests/cutest.h
+++ b/tests/cutest.h
@@ -37,6 +37,10 @@ void die_oom(void);
 
 /* CuTest */
 
+#define CuAssertPositive(tc, n) CuAssertTrue(tc, (n) > 0)
+#define CuAssertZero(tc, n) CuAssertIntEquals(tc, 0, (n))
+#define CuAssertRetSuccess(tc, n) CuAssertIntEquals(tc, 0, (n))
+
 typedef struct CuTest CuTest;
 
 typedef void (*TestFunction)(CuTest *);
diff --git a/tests/test-api.c b/tests/test-api.c
index 322f4a9..368da01 100644
--- a/tests/test-api.c
+++ b/tests/test-api.c
@@ -27,6 +27,8 @@
 #include "cutest.h"
 #include "internal.h"
 
+#include <unistd.h>
+
 static const char *abs_top_srcdir;
 static char *root;
 static char *loadpath;
@@ -222,6 +224,89 @@ static void testDefNodeCreateMeta(CuTest *tc) {
     aug_close(aug);
 }
 
+static void reset_indexes(uint *a, uint *b, uint *c, uint *d, uint *e, uint *f) {
+    *a = 0; *b = 0; *c = 0; *d = 0; *e = 0; *f = 0;
+}
+
+#define SPAN_TEST_DEF_LAST { .expr = NULL, .ls = 0, .le = 0, \
+        .vs = 0, .ve = 0, .ss = 0, .se = 0 }
+
+struct span_test_def {
+    const char *expr;
+    const char *f;
+    int ret;
+    int ls;
+    int le;
+    int vs;
+    int ve;
+    int ss;
+    int se;
+};
+
+static const struct span_test_def span_test[] = {
+    { .expr = "/files/etc/hosts/1/ipaddr", .f = "hosts", .ret = 0, .ls = 0, .le = 0, .vs = 104, .ve = 113, .ss = 104, .se = 113 },
+    { .expr = "/files/etc/hosts/1", .f = "hosts", .ret = 0, .ls = 0, .le = 0, .vs = 0, .ve = 0, .ss = 104, .se = 171 },
+    { .expr = "/files/etc/hosts/#comment[2]", .f = "hosts", .ret = 0, .ls = 0, .le = 0, .vs = 58, .ve = 103, .ss = 56, .se = 104 },
+    { .expr = "/files", .f = NULL, .ret = -1, .ls = 0, .le = 0, .vs = 0, .ve = 0, .ss = 0, .se = 0 },
+    { .expr = "/random", .f = NULL, .ret = -1, .ls = 0, .le = 0, .vs = 0, .ve = 0, .ss = 0, .se = 0 },
+    SPAN_TEST_DEF_LAST
+};
+
+static void testNodeInfo(CuTest *tc) {
+    int ret;
+    int i = 0;
+    struct augeas *aug;
+    struct span_test_def test;
+    char *fbase;
+    char msg[20];
+    static const char *const expr = "/files/etc/hosts/1/ipaddr";
+
+    char *filename_ac;
+    uint label_start, label_end, value_start, value_end, span_start, span_end;
+
+    aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD);
+    ret = aug_load(aug);
+    CuAssertRetSuccess(tc, ret);
+
+    while(span_test[i].expr != NULL) {
+        sprintf(msg, "span_test %d\n", i);
+        test = span_test[i];
+        i++;
+        ret = aug_span(aug, test.expr, &filename_ac, &label_start, &label_end,
+                     &value_start, &value_end, &span_start, &span_end);
+        CuAssertIntEquals_Msg(tc, msg, test.ret, ret);
+        CuAssertIntEquals_Msg(tc, msg, test.ls, label_start);
+        CuAssertIntEquals_Msg(tc, msg, test.le, label_end);
+        CuAssertIntEquals_Msg(tc, msg, test.vs, value_start);
+        CuAssertIntEquals_Msg(tc, msg, test.ve, value_end);
+        CuAssertIntEquals_Msg(tc, msg, test.ss, span_start);
+        CuAssertIntEquals_Msg(tc, msg, test.se, span_end);
+        if (filename_ac != NULL) {
+            fbase = basename(filename_ac);
+        } else {
+            fbase = NULL;
+        }
+        CuAssertStrEquals(tc, test.f, fbase);
+        free(filename_ac);
+        filename_ac = NULL;
+        reset_indexes(&label_start, &label_end, &value_start, &value_end,
+                      &span_start, &span_end);
+    }
+
+    /* test that nodes info are not loaded */
+    aug_close(aug);
+    aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD|AUG_NO_NODE_INDEX);
+    ret = aug_load(aug);
+    CuAssertRetSuccess(tc, ret);
+    ret = aug_span(aug, expr, &filename_ac, &label_start, &label_end,
+                 &value_start, &value_end, &span_start, &span_end);
+    CuAssertIntEquals(tc, -1, ret);
+    reset_indexes(&label_start, &label_end, &value_start, &value_end,
+                  &span_start, &span_end);
+
+    aug_close(aug);
+}
+
 int main(void) {
     char *output = NULL;
     CuSuite* suite = CuSuiteNew();
@@ -232,6 +317,7 @@ int main(void) {
     SUITE_ADD_TEST(suite, testDefVarMeta);
     SUITE_ADD_TEST(suite, testDefNodeExistingMeta);
     SUITE_ADD_TEST(suite, testDefNodeCreateMeta);
+    SUITE_ADD_TEST(suite, testNodeInfo);
 
     abs_top_srcdir = getenv("abs_top_srcdir");
     if (abs_top_srcdir == NULL)
diff --git a/tests/test-load.c b/tests/test-load.c
index 6110ebc..d025900 100644
--- a/tests/test-load.c
+++ b/tests/test-load.c
@@ -27,10 +27,6 @@
 #include "cutest.h"
 #include "internal.h"
 
-#define CuAssertPositive(tc, n) CuAssertTrue(tc, (n) > 0)
-#define CuAssertZero(tc, n) CuAssertIntEquals(tc, 0, (n))
-#define CuAssertRetSuccess(tc, n) CuAssertIntEquals(tc, 0, (n))
-
 static const char *abs_top_srcdir;
 static const char *abs_top_builddir;
 static char *root = NULL;
@@ -488,7 +484,6 @@ int main(void) {
     char *output = NULL;
     CuSuite* suite = CuSuiteNew();
     CuSuiteSetup(suite, NULL, NULL);
-
     SUITE_ADD_TEST(suite, testDefault);
     SUITE_ADD_TEST(suite, testNoLoad);
     SUITE_ADD_TEST(suite, testNoAutoload);
-- 
1.7.1




More information about the augeas-devel mailing list