Skip to content
This repository was archived by the owner on Oct 9, 2018. It is now read-only.

Handling multiple files of the same name #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions instrument.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static void check_contains_file(const char * file1, const char * file2) {
}
}

static void instrument_file(const char * source_file, const char * destination_file, const char * id, int instrumenting) {
static void instrument_file(const char * source_file, const char * destination_file, const char * id, int instrumenting, char * filepath) {
if (g_verbose) {
printf("Instrumenting file %s\n", id);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ static void instrument_file(const char * source_file, const char * destination_f
else if (result == JSCOVERAGE_ERROR_INVALID_BYTE_SEQUENCE) {
fatal("error decoding %s in file %s", jscoverage_encoding, id);
}
jscoverage_instrument_js(id, characters, num_characters, output_stream);
jscoverage_instrument_js(filepath, characters, num_characters, output_stream);
free(characters);

if (fwrite(output_stream->data, 1, output_stream->length, output) != output_stream->length) {
Expand All @@ -135,7 +135,8 @@ void jscoverage_instrument(const char * source,
char ** exclude,
int num_exclude,
char ** no_instrument,
int num_no_instrument)
int num_no_instrument,
char * path)
{
assert(source != NULL);
assert(destination != NULL);
Expand Down Expand Up @@ -215,9 +216,20 @@ void jscoverage_instrument(const char * source,
free(ni);
}

instrument_file(s, d, p->name, instrument_this);
/** make sure the path does not end in a slash. **/
size_t length;
while (string_ends_with(path, "/")) {
length = strlen(path);
path[length-1] = '\0';
}

length = strlen(path) + strlen(p->name) + 2;
char * filepath = malloc(length);
snprintf(filepath, length, "%s/%s", path, p->name);
instrument_file(s, d, p->name, instrument_this, filepath);

cleanup:
free(filepath);
free(s);
free(d);
}
Expand Down
3 changes: 2 additions & 1 deletion instrument.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void jscoverage_instrument(const char * source,
char ** exclude,
int num_exclude,
char ** no_instrument,
int num_no_instrument);
int num_no_instrument,
char * path);

#endif /* INSTRUMENT_H_ */
5 changes: 4 additions & 1 deletion jscoverage.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,20 @@ int main(int argc, char ** argv) {
fatal_command_line("missing argument");
}

char * path;
path = strdup(source);
source = make_canonical_path(source);
destination = make_canonical_path(destination);

jscoverage_init();
jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument);
jscoverage_instrument(source, destination, verbose, exclude, num_exclude, no_instrument, num_no_instrument, path);
jscoverage_cleanup();

free(source);
free(destination);
free(exclude);
free(no_instrument);
free(path);

exit(EXIT_SUCCESS);
}