summaryrefslogtreecommitdiff
path: root/ext/testcase.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/testcase.c')
-rw-r--r--ext/testcase.c256
1 files changed, 125 insertions, 131 deletions
diff --git a/ext/testcase.c b/ext/testcase.c
index b815c56..dad6503 100644
--- a/ext/testcase.c
+++ b/ext/testcase.c
@@ -576,6 +576,8 @@ testcase_str2dep_complex(Pool *pool, const char **sp, int relop)
Id flags, id, id2, namespaceid = 0;
struct oplist *op;
+ if (!s)
+ return 0;
while (*s == ' ' || *s == '\t')
s++;
if (!strncmp(s, "namespace:", 10))
@@ -964,11 +966,101 @@ str2jobflags(Pool *pool, char *s) /* modifies the string */
return jobflags;
}
+static Id
+testcase_str2jobsel(Pool *pool, const char *caller, char **pieces, int npieces, Id *whatp)
+{
+ Id job, what;
+ if (!strcmp(pieces[0], "pkg") && npieces == 2)
+ {
+ job = SOLVER_SOLVABLE;
+ what = testcase_str2solvid(pool, pieces[1]);
+ if (!what)
+ return pool_error(pool, -1, "%s: unknown package '%s'", caller, pieces[1]);
+ }
+ else if (!strcmp(pieces[0], "name") || !strcmp(pieces[0], "provides"))
+ {
+ /* join em again for dep2str... */
+ char *sp;
+ for (sp = pieces[1]; sp < pieces[npieces - 1]; sp++)
+ if (*sp == 0)
+ *sp = ' ';
+ what = 0;
+ if (pieces[0][0] == 'p' && strncmp(pieces[1], "namespace:", 10) == 0)
+ {
+ char *spe = strchr(pieces[1], '(');
+ int l = strlen(pieces[1]);
+ if (spe && pieces[1][l - 1] == ')')
+ {
+ /* special namespace provides */
+ if (strcmp(spe, "(<NULL>)") != 0)
+ {
+ pieces[1][l - 1] = 0;
+ what = testcase_str2dep(pool, spe + 1);
+ pieces[1][l - 1] = ')';
+ }
+ what = pool_rel2id(pool, pool_strn2id(pool, pieces[1], spe - pieces[1], 1), what, REL_NAMESPACE, 1);
+ }
+ }
+ if (!what)
+ what = testcase_str2dep(pool, pieces[1]);
+ if (pieces[0][0] == 'n')
+ job = SOLVER_SOLVABLE_NAME;
+ else
+ job = SOLVER_SOLVABLE_PROVIDES;
+ }
+ else if (!strcmp(pieces[0], "oneof"))
+ {
+ Queue q;
+ job = SOLVER_SOLVABLE_ONE_OF;
+ queue_init(&q);
+ if (npieces > 1 && strcmp(pieces[1], "nothing") != 0)
+ {
+ int i;
+ for (i = 1; i < npieces; i++)
+ {
+ Id p = testcase_str2solvid(pool, pieces[i]);
+ if (!p)
+ {
+ queue_free(&q);
+ return pool_error(pool, -1, "%s: unknown package '%s'", caller, pieces[i]);
+ }
+ queue_push(&q, p);
+ }
+ }
+ what = pool_queuetowhatprovides(pool, &q);
+ queue_free(&q);
+ }
+ else if (!strcmp(pieces[0], "repo") && npieces == 2)
+ {
+ Repo *repo = testcase_str2repo(pool, pieces[1]);
+ if (!repo)
+ return pool_error(pool, -1, "%s: unknown repo '%s'", caller, pieces[1]);
+ job = SOLVER_SOLVABLE_REPO;
+ what = repo->repoid;
+ }
+ else if (!strcmp(pieces[0], "all") && npieces == 2 && !strcmp(pieces[1], "packages"))
+ {
+ job = SOLVER_SOLVABLE_ALL;
+ what = 0;
+ }
+ else
+ {
+ /* join em again for the error message... */
+ char *sp;
+ for (sp = pieces[0]; sp < pieces[npieces - 1]; sp++)
+ if (*sp == 0)
+ *sp = ' ';
+ return pool_error(pool, -1, "%s: bad line '%s'", caller, pieces[0]);
+ }
+ *whatp = what;
+ return job;
+}
+
Id
testcase_str2job(Pool *pool, const char *str, Id *whatp)
{
int i;
- Id job;
+ Id job, jobsel;
Id what;
char *s;
char **pieces = 0;
@@ -1020,116 +1112,12 @@ testcase_str2job(Pool *pool, const char *str, Id *whatp)
job |= str2jobflags(pool, flags);
}
}
- if (!strcmp(pieces[1], "pkg"))
- {
- if (npieces != 3)
- {
- pool_error(pool, -1, "str2job: bad pkg selector in '%s'", str);
- solv_free(pieces);
- return -1;
- }
- job |= SOLVER_SOLVABLE;
- what = testcase_str2solvid(pool, pieces[2]);
- if (!what)
- {
- pool_error(pool, -1, "str2job: unknown package '%s'", pieces[2]);
- solv_free(pieces);
- return -1;
- }
- }
- else if (!strcmp(pieces[1], "name") || !strcmp(pieces[1], "provides"))
- {
- /* join em again for dep2str... */
- char *sp;
- for (sp = pieces[2]; sp < pieces[npieces - 1]; sp++)
- if (*sp == 0)
- *sp = ' ';
- what = 0;
- if (pieces[1][0] == 'p' && strncmp(pieces[2], "namespace:", 10) == 0)
- {
- char *spe = strchr(pieces[2], '(');
- int l = strlen(pieces[2]);
- if (spe && pieces[2][l - 1] == ')')
- {
- /* special namespace provides */
- if (strcmp(spe, "(<NULL>)") != 0)
- {
- pieces[2][l - 1] = 0;
- what = testcase_str2dep(pool, spe + 1);
- pieces[2][l - 1] = ')';
- }
- what = pool_rel2id(pool, pool_strn2id(pool, pieces[2], spe - pieces[2], 1), what, REL_NAMESPACE, 1);
- }
- }
- if (!what)
- what = testcase_str2dep(pool, pieces[2]);
- if (pieces[1][0] == 'n')
- job |= SOLVER_SOLVABLE_NAME;
- else
- job |= SOLVER_SOLVABLE_PROVIDES;
- }
- else if (!strcmp(pieces[1], "oneof"))
- {
- Queue q;
- job |= SOLVER_SOLVABLE_ONE_OF;
- queue_init(&q);
- if (npieces > 2 && strcmp(pieces[2], "nothing") != 0)
- {
- for (i = 2; i < npieces; i++)
- {
- Id p = testcase_str2solvid(pool, pieces[i]);
- if (!p)
- {
- pool_error(pool, -1, "str2job: unknown package '%s'", pieces[i]);
- queue_free(&q);
- solv_free(pieces);
- return -1;
- }
- queue_push(&q, p);
- }
- }
- what = pool_queuetowhatprovides(pool, &q);
- queue_free(&q);
- }
- else if (!strcmp(pieces[1], "repo"))
- {
- Repo *repo;
- if (npieces != 3)
- {
- pool_error(pool, -1, "str2job: bad line '%s'", str);
- solv_free(pieces);
- return -1;
- }
- repo = testcase_str2repo(pool, pieces[2]);
- if (!repo)
- {
- pool_error(pool, -1, "str2job: unknown repo '%s'", pieces[2]);
- solv_free(pieces);
- return -1;
- }
- job |= SOLVER_SOLVABLE_REPO;
- what = repo->repoid;
- }
- else if (!strcmp(pieces[1], "all"))
- {
- if (npieces != 3 && strcmp(pieces[2], "packages") != 0)
- {
- pool_error(pool, -1, "str2job: bad line '%s'", str);
- solv_free(pieces);
- return -1;
- }
- job |= SOLVER_SOLVABLE_ALL;
- what = 0;
- }
- else
- {
- pool_error(pool, -1, "str2job: unknown selection in '%s'", str);
- solv_free(pieces);
- return -1;
- }
- *whatp = what;
+ jobsel = testcase_str2jobsel(pool, "str2job", pieces + 1, npieces - 1, &what);
solv_free(pieces);
- return job;
+ if (jobsel == -1)
+ return -1;
+ *whatp = what;
+ return job | jobsel;
}
#define SELECTIONJOB_MATCHDEPS 1
@@ -1816,6 +1804,7 @@ static struct rclass2str {
{ SOLVER_RULE_LEARNT, "learnt" },
{ SOLVER_RULE_BEST, "best" },
{ SOLVER_RULE_YUMOBS, "yumobs" },
+ { SOLVER_RULE_RECOMMENDS, "recommends" },
{ 0, 0 }
};
@@ -2023,6 +2012,8 @@ testcase_solverresult(Solver *solv, int resultflags)
/* map choice rules back to pkg rules */
if (solver_ruleclass(solv, id) == SOLVER_RULE_CHOICE)
id = solver_rule2pkgrule(solv, id);
+ if (solver_ruleclass(solv, id) == SOLVER_RULE_RECOMMENDS)
+ id = solver_rule2pkgrule(solv, id);
solver_allruleinfos(solv, id, &rq);
for (i = 0; i < rq.count; i += 4)
{
@@ -2187,7 +2178,7 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
Id lowscore;
FILE *fp;
Strqueue sq;
- char *cmd, *out;
+ char *cmd, *out, *result;
const char *s;
if (!testcasename)
@@ -2322,7 +2313,6 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
if ((resultflags & ~TESTCASE_RESULT_REUSE_SOLVER) != 0)
{
- char *result;
cmd = 0;
for (i = 0; resultflags2str[i].str; i++)
if ((resultflags & resultflags2str[i].flag) != 0)
@@ -2333,7 +2323,6 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
result = testcase_solverresult(solv, resultflags);
if (!strcmp(resultname, "<inline>"))
{
- int i;
Strqueue rsq;
strqueue_init(&rsq);
strqueue_split(&rsq, result);
@@ -2365,6 +2354,7 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
if (fclose(fp))
{
pool_error(solv->pool, 0, "testcase_write: write error");
+ solv_free(result);
strqueue_free(&sq);
return 0;
}
@@ -2372,29 +2362,29 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
solv_free(result);
}
- cmd = strqueue_join(&sq);
+ result = strqueue_join(&sq);
+ strqueue_free(&sq);
out = pool_tmpjoin(pool, dir, "/", testcasename);
if (!(fp = fopen(out, "w")))
{
pool_error(solv->pool, 0, "testcase_write: could not open '%s' for writing", out);
- strqueue_free(&sq);
+ solv_free(result);
return 0;
}
- if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
+ if (*result && fwrite(result, strlen(result), 1, fp) != 1)
{
pool_error(solv->pool, 0, "testcase_write: write error");
- strqueue_free(&sq);
+ solv_free(result);
fclose(fp);
return 0;
}
if (fclose(fp))
{
pool_error(solv->pool, 0, "testcase_write: write error");
- strqueue_free(&sq);
+ solv_free(result);
return 0;
}
- solv_free(cmd);
- strqueue_free(&sq);
+ solv_free(result);
return 1;
}
@@ -2789,7 +2779,7 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
{
int i = strlen(pieces[1]);
s = strchr(pieces[1], '(');
- if (!s && pieces[1][i - 1] != ')')
+ if (!s || pieces[1][i - 1] != ')')
{
pool_error(pool, 0, "testcase_read: bad namespace '%s'", pieces[1]);
}
@@ -2877,12 +2867,7 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
}
else if (!strcmp(pieces[0], "disable") && npieces == 3)
{
- Id p;
- if (strcmp(pieces[1], "pkg"))
- {
- pool_error(pool, 0, "testcase_read: bad disable type '%s'", pieces[1]);
- continue;
- }
+ Id p, pp, jobsel, what = 0;
if (!prepared)
pool_createwhatprovides(pool);
prepared = -1;
@@ -2892,11 +2877,20 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
map_init(pool->considered, pool->nsolvables);
map_setall(pool->considered);
}
- p = testcase_str2solvid(pool, pieces[2]);
- if (p)
+ jobsel = testcase_str2jobsel(pool, "disable", pieces + 1, npieces - 1, &what);
+ if (jobsel < 0)
+ continue;
+ if (jobsel == SOLVER_SOLVABLE_ALL)
+ map_empty(pool->considered);
+ else if (jobsel == SOLVER_SOLVABLE_REPO)
+ {
+ Repo *repo = pool_id2repo(pool, what);
+ Solvable *s;
+ FOR_REPO_SOLVABLES(repo, p, s)
+ MAPCLR(pool->considered, p);
+ }
+ FOR_JOB_SELECT(p, pp, jobsel, what)
MAPCLR(pool->considered, p);
- else
- pool_error(pool, 0, "disable: unknown package '%s'", pieces[2]);
}
else if (!strcmp(pieces[0], "feature"))
{