Commit 7b81d8c2 authored by Justin Goshi's avatar Justin Goshi Committed by Brad King
Browse files

TestGenerator: Record support file and line where test was added

Add internal test properties that ctest can use to report where
the test was added in CMake code.
parent 00530d74
......@@ -2147,6 +2147,32 @@ bool cmCTestTestHandler::SetTestsProperties(
for (std::string const& t : tests) {
for (cmCTestTestProperties& rt : this->TestList) {
if (t == rt.Name) {
if (key == "_BACKTRACE_TRIPLES") {
std::vector<std::string> triples;
// allow empty args in the triples
cmSystemTools::ExpandListArgument(val, triples, true);
// Ensure we have complete triples otherwise the data is corrupt.
if (triples.size() % 3 == 0) {
cmState state;
rt.Backtrace = cmListFileBacktrace(state.CreateBaseSnapshot());
// the first entry represents the top of the trace so we need to
// reconstruct the backtrace in reverse
for (size_t i = triples.size(); i >= 3; i -= 3) {
cmListFileContext fc;
fc.FilePath = triples[i - 3];
long line = 0;
if (!cmSystemTools::StringToLong(triples[i - 2].c_str(),
&line)) {
line = 0;
}
fc.Line = line;
fc.Name = triples[i - 1];
rt.Backtrace = rt.Backtrace.Push(fc);
}
}
}
if (key == "WILL_FAIL") {
rt.WillFail = cmSystemTools::IsOn(val);
}
......
......@@ -7,6 +7,7 @@
#include "cmCTestGenericHandler.h"
#include "cmDuration.h"
#include "cmListFileCache.h"
#include "cmsys/RegularExpression.hxx"
#include <chrono>
......@@ -141,6 +142,8 @@ public:
std::set<std::string> FixturesCleanup;
std::set<std::string> FixturesRequired;
std::set<std::string> RequireSuccessDepends;
// Private test generator properties used to track backtraces
cmListFileBacktrace Backtrace;
};
struct cmCTestTestResult
......
......@@ -7,14 +7,16 @@
#include "cmGeneratorExpression.h"
#include "cmGeneratorTarget.h"
#include "cmListFileCache.h"
#include "cmLocalGenerator.h"
#include "cmOutputConverter.h"
#include "cmProperty.h"
#include "cmPropertyMap.h"
#include "cmStateTypes.h"
#include "cmSystemTools.h"
#include "cmTest.h"
class cmPropertyMap;
cmTestGenerator::cmTestGenerator(
cmTest* test, std::vector<std::string> const& configurations)
: cmScriptGenerator("CTEST_CONFIGURATION_TYPE", configurations)
......@@ -121,16 +123,15 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
// Output properties for the test.
cmPropertyMap& pm = this->Test->GetProperties();
if (!pm.empty()) {
os << indent << "set_tests_properties(" << this->Test->GetName()
<< " PROPERTIES ";
for (auto const& i : pm) {
os << " " << i.first << " "
<< cmOutputConverter::EscapeForCMake(
ge.Parse(i.second.GetValue())->Evaluate(this->LG, config));
}
os << ")" << std::endl;
os << indent << "set_tests_properties(" << this->Test->GetName()
<< " PROPERTIES ";
for (auto const& i : pm) {
os << " " << i.first << " "
<< cmOutputConverter::EscapeForCMake(
ge.Parse(i.second.GetValue())->Evaluate(this->LG, config));
}
this->GenerateInternalProperties(os);
os << ")" << std::endl;
}
void cmTestGenerator::GenerateScriptNoConfig(std::ostream& os, Indent indent)
......@@ -179,13 +180,37 @@ void cmTestGenerator::GenerateOldStyle(std::ostream& fout, Indent indent)
// Output properties for the test.
cmPropertyMap& pm = this->Test->GetProperties();
if (!pm.empty()) {
fout << indent << "set_tests_properties(" << this->Test->GetName()
<< " PROPERTIES ";
for (auto const& i : pm) {
fout << " " << i.first << " "
<< cmOutputConverter::EscapeForCMake(i.second.GetValue());
fout << indent << "set_tests_properties(" << this->Test->GetName()
<< " PROPERTIES ";
for (auto const& i : pm) {
fout << " " << i.first << " "
<< cmOutputConverter::EscapeForCMake(i.second.GetValue());
}
this->GenerateInternalProperties(fout);
fout << ")" << std::endl;
}
void cmTestGenerator::GenerateInternalProperties(std::ostream& os)
{
cmListFileBacktrace bt = this->Test->GetBacktrace();
if (bt.Empty()) {
return;
}
os << " "
<< "_BACKTRACE_TRIPLES"
<< " \"";
bool prependTripleSeparator = false;
while (!bt.Empty()) {
const auto& entry = bt.Top();
if (prependTripleSeparator) {
os << ";";
}
fout << ")" << std::endl;
os << entry.FilePath << ";" << entry.Line << ";" << entry.Name;
bt = bt.Pop();
prependTripleSeparator = true;
}
os << "\"";
}
......@@ -35,6 +35,9 @@ public:
cmTest* GetTest() const;
private:
void GenerateInternalProperties(std::ostream& os);
protected:
void GenerateScriptConfigs(std::ostream& os, Indent indent) override;
void GenerateScriptActions(std::ostream& os, Indent indent) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment