static void cover_report_file(cover_file_t *f, const char *dir) { char buf[256]; snprintf(buf, sizeof(buf), "%s/%s", dir, cover_file_url(f)); FILE *fp = lib_fopen(lib_work(), buf, "w"); if (fp == NULL) fatal("failed to create %s", buf); fprintf(fp, "<html>\n" "<head>\n" " <title>Coverage report for %s</title>\n" "</head>\n" "<body>\n", f->name); fprintf(fp, "<table>\n"); for (int i = 0; i < f->n_lines; i++) { cover_line_t *l = &(f->lines[i]); cover_report_line(fp, l); } fprintf(fp, "</table>\n"); fprintf(fp, "<body>\n</html>\n"); fclose(fp); }
static void cover_index(ident_t name, const char *dir) { char buf[256]; snprintf(buf, sizeof(buf), "%s/index.html", dir); FILE *fp = lib_fopen(lib_work(), buf, "w"); if (fp == NULL) fatal("failed to create %s", buf); fprintf(fp, "<html>\n" "<head>\n" " <title>Coverage report for %s</title>\n" "</head>\n" "<body>\n", istr(name)); fprintf(fp, "<ul>\n"); for (cover_file_t *f = files; f != NULL; f = f->next) { fprintf(fp, "<li><a href=\"%s\">%s</a></li>\n", cover_file_url(f), f->name); } fprintf(fp, "</ul>\n"); fprintf(fp, "<body>\n</html>\n"); fclose(fp); }
END_TEST START_TEST(test_lib_fopen) { FILE *f = lib_fopen(work, "_test", "w"); fprintf(f, "hello world"); fclose(f); lib_free(work); work = lib_find("work", false, false); fail_if(work == NULL); f = lib_fopen(work, "_test", "r"); char buf[12]; fgets(buf, sizeof(buf), f); fail_unless(strcmp(buf, "hello world") == 0); fclose(f); }
END_TEST START_TEST(test_lib_fopen) { FILE *f = lib_fopen(work, "_test", "w"); fprintf(f, "hello world"); fclose(f); lib_free(work); lib_add_search_path("/tmp"); work = lib_find(ident_new("test_lib"), false); fail_if(work == NULL); f = lib_fopen(work, "_test", "r"); fail_if(f == NULL); char buf[12]; fail_if(fgets(buf, sizeof(buf), f) == NULL); fail_unless(strcmp(buf, "hello world") == 0); fclose(f); }