* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#define _GNU_SOURCE /* for asprintf */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ecoli_malloc.h>
#include <ecoli_log.h>
+#include <ecoli_string.h>
#include <ecoli_test.h>
#include <ecoli_strvec.h>
#include <ecoli_node.h>
new_vec = tokenize(str, 0, 0, NULL);
}
if (new_vec == NULL) {
- ret = -ENOMEM;
+ if (errno == EINVAL)
+ ret = EC_PARSED_NOMATCH;
+ else
+ ret = -ENOMEM;
goto fail;
}
goto fail;
while ((item = ec_completed_iter_next(iter)) != NULL) {
str = ec_completed_item_get_str(item);
- if (asprintf(&new_str, "%c%s%c", missing_quote, str,
+ if (ec_asprintf(&new_str, "%c%s%c", missing_quote, str,
missing_quote) < 0) {
new_str = NULL;
goto fail;
}
if (ec_completed_item_set_str(item, new_str) < 0)
goto fail;
- free(new_str);
+ ec_free(new_str);
new_str = NULL;
str = ec_completed_item_get_completion(item);
- if (asprintf(&new_str, "%s%c", str,
+ if (ec_asprintf(&new_str, "%s%c", str,
missing_quote) < 0) {
new_str = NULL;
goto fail;
}
if (ec_completed_item_set_completion(item, new_str) < 0)
goto fail;
- free(new_str);
+ ec_free(new_str);
new_str = NULL;
}
}
ec_completed_free(tmp_completed);
ec_completed_iter_free(iter);
ec_strvec_free(new_vec);
- free(new_str);
+ ec_free(new_str);
return -1;
}
static int ec_node_sh_lex_testcase(void)
{
struct ec_node *node;
- int ret = 0;
+ int testres = 0;
node = ec_node_sh_lex(EC_NO_ID,
EC_NODE_SEQ(EC_NO_ID,
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " foo bar");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " 'foo' \"bar\"");
- ret |= EC_TEST_CHECK_PARSE(node, 1, " 'f'oo 'toto' bar");
- ret |= EC_TEST_CHECK_PARSE(node, -1, " foo toto bar'");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, "foo bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " foo bar");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " 'foo' \"bar\"");
+ testres |= EC_TEST_CHECK_PARSE(node, 1, " 'f'oo 'toto' bar");
+ testres |= EC_TEST_CHECK_PARSE(node, -1, " foo toto bar'");
ec_node_free(node);
/* test completion */
EC_LOG(EC_LOG_ERR, "cannot create node\n");
return -1;
}
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
" ", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"f", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo", EC_NODE_ENDLIST,
"foo", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo ", EC_NODE_ENDLIST,
"bar", "toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo t", EC_NODE_ENDLIST,
"toto", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo b", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo bar", EC_NODE_ENDLIST,
"bar", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo bar ", EC_NODE_ENDLIST,
"titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo toto bar ", EC_NODE_ENDLIST,
"titi", EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"x", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo barx", EC_NODE_ENDLIST,
EC_NODE_ENDLIST);
- ret |= EC_TEST_CHECK_COMPLETE(node,
+ testres |= EC_TEST_CHECK_COMPLETE(node,
"foo 'b", EC_NODE_ENDLIST,
"'bar'", EC_NODE_ENDLIST);
ec_node_free(node);
- return ret;
+ return testres;
}
/* LCOV_EXCL_STOP */