diff --git a/src/configuration.cc b/src/configuration.cc index c186c7ed..26b6064e 100644 --- a/src/configuration.cc +++ b/src/configuration.cc @@ -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", ""); @@ -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 @@ -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() diff --git a/src/writers/coveralls-writer.cc b/src/writers/coveralls-writer.cc index aad5ca5d..2f963233 100644 --- a/src/writers/coveralls-writer.cc +++ b/src/writers/coveralls-writer.cc @@ -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 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--;