Skip to content

Commit

Permalink
Issue #358: coveralls-writer: Upload source if the coveralls-source k…
Browse files Browse the repository at this point in the history
…ey is set
  • Loading branch information
SimonKagstrom committed Feb 11, 2022
1 parent 8419da5 commit 64bdb19
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ class Configuration : public IConfiguration
setKey("output-interval", 5000);
setKey("daemonize-on-first-process-exit", 0);
setKey("coveralls-id", "");
setKey("coveralls-source", 0);
setKey("strip-path", "");
setKey("exclude-line", "");
setKey("exclude-region", "");
Expand Down Expand Up @@ -690,6 +691,8 @@ class Configuration : public IConfiguration
setKey(key, std::string(value));
else if (key == "coveralls-service-name")
setKey(key, std::string(value));
else if (key == "coveralls-source")
setKey(key, stoul(value));
else if (key == "cobertura-full-paths")
setKey(key, stoul(std::string(value)));
else
Expand All @@ -704,7 +707,9 @@ class Configuration : public IConfiguration
" high-limit=NUM Percentage for high coverage\n"
" low-limit=NUM Percentage for low coverage\n"
" merged-name=STR Name of [merged] tag in HTML\n"
" coveralls-service-name=STR Service name for coveralls\n";
" coveralls-service-name=STR Service name for coveralls\n"
" coveralls-source=1 Upload actual source code\n"
;
}

std::string uncommonOptions()
Expand Down
27 changes: 26 additions & 1 deletion src/writers/coveralls-writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,32 @@ class CoverallsWriter : public WriterBase
if (n != file->m_lastLineNr - 1)
out << ",";
}
out << "]\n";
out << "]";

if (conf.keyAsInt("coveralls-source"))
{
out << ",\n";

size_t sz = 0;
char *p = (char *)read_file(&sz, "%s", file->m_name.c_str());
if (p)
{
std::vector<std::string> lines = split_string(std::string(p), "\n");
out << " \"source\": [";
for (unsigned i = 0; i < lines.size(); i++)
{
std::string line = escape_json(lines[i]);
out << "\"" + line + "\"";
if (i != lines.size() - 1)
{
out << ",";
}
}
out << "]";
}
free(p);
}
out << "\n";

// Add comma or not on the last run
filesLeft--;
Expand Down

0 comments on commit 64bdb19

Please sign in to comment.