aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/deliverable.c19
-rw-r--r--src/main.c1
-rw-r--r--src/utils.c58
3 files changed, 77 insertions, 1 deletions
diff --git a/src/deliverable.c b/src/deliverable.c
index 0ddf17a..0b166d9 100644
--- a/src/deliverable.c
+++ b/src/deliverable.c
@@ -1393,6 +1393,20 @@ void delivery_tests_run(struct Delivery *ctx) {
msg(OMC_MSG_L3, "Testing %s\n", ctx->tests[i].name);
memset(&proc, 0, sizeof(proc));
+ // Apply workaround for tox positional arguments
+ char *toxconf = NULL;
+ if (!access("tox.ini", F_OK)) {
+ msg(OMC_MSG_L3, "Fixing tox positional arguments\n");
+
+ fix_tox_conf("tox.ini", &toxconf);
+ if (!globals.workaround.tox_posargs) {
+ globals.workaround.tox_posargs = calloc(PATH_MAX, sizeof(*globals.workaround.tox_posargs));
+ } else {
+ memset(globals.workaround.tox_posargs, 0, PATH_MAX);
+ }
+ snprintf(globals.workaround.tox_posargs, PATH_MAX - 1, "-c %s --root .", toxconf);
+ }
+
// enable trace mode before executing each test script
memset(cmd, 0, sizeof(cmd));
sprintf(cmd, "set -x ; %s", ctx->tests[i].script);
@@ -1410,6 +1424,11 @@ void delivery_tests_run(struct Delivery *ctx) {
msg(OMC_MSG_ERROR, "Script failure: %s\n%s\n\nExit code: %d\n", ctx->tests[i].name, ctx->tests[i].script, status);
COE_CHECK_ABORT(!globals.continue_on_error, "Test failure")
}
+
+ if (toxconf) {
+ remove(toxconf);
+ guard_free(toxconf);
+ }
popd();
#else
msg(OMC_MSG_WARNING | OMC_MSG_L3, "TESTING DISABLED BY CODE!\n");
diff --git a/src/main.c b/src/main.c
index b7b4e3f..a2682ac 100644
--- a/src/main.c
+++ b/src/main.c
@@ -254,6 +254,7 @@ int main(int argc, char *argv[], char *arge[]) {
tpl_register("system.platform", &ctx.system.platform[DELIVERY_PLATFORM_RELEASE]);
tpl_register("deploy.jfrog.repo", &globals.jfrog.repo);
tpl_register("deploy.docker.registry", &ctx.deploy.docker.registry);
+ tpl_register("workaround.tox_posargs", &globals.workaround.tox_posargs);
// Set up PREFIX/etc directory information
// The user may manipulate the base directory path with OMC_SYSCONFDIR
diff --git a/src/utils.c b/src/utils.c
index 047a266..85a3b56 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -590,4 +590,60 @@ int xml_pretty_print_in_place(const char *filename, const char *pretty_print_pro
guard_free(tempfile);
guard_free(result);
return -1;
-} \ No newline at end of file
+}
+
+int fix_tox_conf(const char *filename, char **result) {
+ struct INIFILE *toxini;
+ FILE *fptemp;
+ char *tempfile;
+ const char *with_posargs = " \\\n {posargs}\n";
+
+ tempfile = xmkstemp(&fptemp, "w+");
+ if (!tempfile) {
+ return -1;
+ }
+
+ if (!*result) {
+ *result = calloc(PATH_MAX, sizeof(*result));
+ if (!*result) {
+ return -1;
+ }
+ }
+
+ toxini = ini_open(filename);
+ if (!toxini) {
+ if (fptemp) {
+ guard_free(tempfile);
+ fclose(fptemp);
+ }
+ guard_free(*result);
+ return -1;
+ }
+
+ for (size_t i = 0; i < toxini->section_count; i++) {
+ struct INISection *section = toxini->section[i];
+ if (section) {
+ if (startswith(section->key, "testenv")) {
+ for (size_t k = 0; k < section->data_count; k++) {
+ struct INIData *data = section->data[k];
+ if (data) {
+ if (!strcmp(data->key, "commands") && (startswith(data->value, "pytest") && !strstr(data->value, "{posargs}"))) {
+ strip(data->value);
+ data->value = realloc(data->value, strlen(data->value) + strlen(with_posargs) + 1);
+ strcat(data->value, with_posargs);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (ini_write(toxini, &fptemp)) {
+ guard_free(tempfile);
+ }
+ fclose(fptemp);
+
+ *result = tempfile;
+ ini_free(&toxini);
+ return 0;
+}