Skip to content

Commit c0c1777

Browse files
backend 1.2.1: mtest's cases read with mtest's own static manifest, across the project's suite types (#7)
The backend reads mtest's cases with mcpplibs.mtest.manifest 0.4.1, with the suite types the project's tests declare under tests/; the backend states its version 1.2.1; the CLion archive is named by the plugin's own version. Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
1 parent 00b9bd6 commit c0c1777

7 files changed

Lines changed: 81 additions & 54 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ jobs:
616616
- name: The Marketplace submission would name this verified plugin
617617
run: |
618618
set -euo pipefail
619-
version="$(sed -n 's/^version *= *"\(.*\)"/\1/p' mcpp.toml | head -1)"
619+
# The plugin's own version: a component's patch moves it apart from the backend's (mcpp.toml).
620+
version="$(sed -n 's/^pluginVersion *= *//p' mide-plugins/clion/gradle.properties | head -1)"
620621
archive="mide-plugins/clion/build/distributions/mcpp-clion-$version.zip"
621622
test -f "$archive"
622623
digest="$(sha256sum "$archive" | cut -d ' ' -f1)"

‎CHANGELOG.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ The changelog is kept by series (`X.Y`); each section lists its components' rele
44

55
## 1.2
66

7+
### backend 1.2.1
8+
9+
- **mtest's cases as mtest reads them.** The cases of a file of mtest are read with mtest's own
10+
static manifest (`mcpplibs.mtest.manifest` 0.4.1) instead of a reader of the backend's: an object
11+
(`UTest parse{"parse", [] { ... }}`, and `Suite`, `CTS`, `E2E`, `Bench` or a suite type derived from
12+
one) is a case, and so is each `"name"_test` it declares, under its name. A suite type the project's
13+
tests declare in a module beside them (`class Fixture : public CTS` in `tests/cts/cts.cppm`) is read
14+
from `tests/` and holds in every file that uses it. A file written for mtest 0.3 or 0.4 shows its
15+
cases before it is built, as one written for 0.2 did.
16+
717
### 1.2.0
818

919
The first series of one version for every component: the backend, mcpp-vscode, mcpp-clion and

‎mcpp.lock‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ source = "index+mcpplibs@0.4.0"
8181
hash = "fnv1a:c06e4aa4f73f1f27"
8282
targets = ["aarch64-openkal", "x86_64-linux-gnu", "x86_64-openkal"]
8383

84+
[package."mcpplibs.mtest.manifest"]
85+
namespace = "mcpplibs.mtest"
86+
version = "0.4.1"
87+
source = "index+mcpplibs.mtest@0.4.1"
88+
hash = "fnv1a:0339d37dd3c40581"
89+
8490
[package."nlohmann.json"]
8591
namespace = "nlohmann"
8692
version = "3.12.0"

‎mcpp.toml‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
# M2/M3), where the system it runs upon is answered when the image is loaded.
1010
[package]
1111
name = "mcpp-ide"
12-
version = "1.2.0"
12+
version = "1.2.1"
1313
description = "The IDE backend for mcpp: sessions, jobs, records and view models over mcpp's control contract"
1414
license = "Apache-2.0"
1515
authors = ["mcpp-community"]
@@ -80,6 +80,8 @@ main = "src/bin/dev.cpp"
8080
# runtime and loader remain the platform's.
8181
mcpplibs.os = "0.4.0"
8282
nlohmann.json = "3.12.0"
83+
# mtest's static case manifest: the cases a test file declares, read as mtest reads them.
84+
mcpplibs.mtest.manifest = "0.4.1"
8385

8486
# What every backend test shares (testsupport/): a module, as the backend's units are.
8587
[dev-dependencies]

‎src/scan.cppm‎

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
export module mcppide.scan;
1414

1515
import std;
16+
import mcpplibs.mtest.manifest;
1617

1718
export namespace mcppide::scan {
1819

@@ -25,8 +26,10 @@ struct Call {
2526
std::vector<std::string> arguments;
2627
};
2728

28-
// A case of the mtest library (`"name"_test`): its identifier -- the names of the suites it is
29-
// declared in and its own, joined by `/` -- and where its name is (0-based).
29+
// A case of the mtest library -- an object (`UTest parse{"parse", ...}`, any suite type) or a
30+
// `"name"_test` declared in one -- as mtest's own static manifest reads it
31+
// (mcpplibs.mtest.manifest): its identifier, the names of what declares it and its own joined by
32+
// `/`, and where its name is (0-based).
3033
struct Literal {
3134
std::string id;
3235
int line = 0;
@@ -36,11 +39,13 @@ struct Literal {
3639
struct Result {
3740
std::optional<int> mainLine; // 0-based
3841
std::vector<Call> calls;
39-
std::vector<Literal> cases; // `"name"_test`, in `suite x{"name", ...}` scopes
42+
std::vector<Literal> cases; // mtest's cases, by mcpplibs.mtest.manifest
4043
};
4144

42-
// Scans `text` for `main` and for calls of the macros named in `macros`.
43-
Result scan(std::string_view text, const std::vector<std::string>& macros);
45+
// Scans `text` for `main` and for calls of the macros named in `macros`. `types` are the suite types
46+
// the project's tests declare elsewhere (`class Fixture : public CTS` in a module beside them).
47+
Result scan(std::string_view text, const std::vector<std::string>& macros,
48+
const mcpplibs::mtest::manifest::suite_types& types = {});
4449

4550
// A string literal's contents, as the program sees them for the plain escapes (\" \\ \n \t); the
4651
// argument itself when it is not one literal. Adjacent literals are joined.
@@ -157,24 +162,14 @@ std::vector<std::string> arguments(Cursor& c) {
157162

158163
} // namespace
159164

160-
Result scan(std::string_view text, const std::vector<std::string>& macros) {
165+
Result scan(std::string_view text, const std::vector<std::string>& macros,
166+
const mcpplibs::mtest::manifest::suite_types& types) {
161167
Result r;
162168
Cursor c{text};
163169
int depth = 0; // braces
164170
bool atDeclaration = true; // the next identifier starts a declaration
165171
bool lineHasCode = false; // a `#` is a directive only first on its line
166172
std::string previous; // the previous identifier, for `int main(`
167-
// A suite of the mtest library: `suite <name>{"<id>", ...}`, whose `{` opens the scope its
168-
// cases' identifiers are prefixed in. `suiteState` follows the declaration: 1 after `suite`,
169-
// 2 after its variable's name, 3 after the `{` (the next literal is the suite's identifier).
170-
struct Scope { std::string name; int depth; };
171-
std::vector<Scope> suites;
172-
int suiteState = 0, suiteDepth = 0;
173-
auto prefix = [&] {
174-
std::string out;
175-
for (const auto& s : suites) if (!s.name.empty()) out += s.name + "/";
176-
return out;
177-
};
178173
while (!c.done()) {
179174
const char ch = c.peek();
180175
if (ch == '\n') { lineHasCode = false; c.step(); continue; }
@@ -185,16 +180,7 @@ Result scan(std::string_view text, const std::vector<std::string>& macros) {
185180
lineHasCode = true;
186181
if (c.on_raw()) { c.skip_raw(); atDeclaration = false; previous.clear(); continue; }
187182
if (ch == '"') {
188-
const auto from = c.at;
189-
const int line = c.line, column = c.column();
190183
c.skip_quoted(ch);
191-
const auto value = literal_value(text.substr(from, c.at - from));
192-
if (suiteState == 3) {
193-
suites.push_back({value, suiteDepth});
194-
suiteState = 0;
195-
} else if (text.substr(c.at, 5) == "_test" && !(c.at + 5 < text.size() && ident_char(text[c.at + 5]))) {
196-
r.cases.push_back(Literal{prefix() + value, line, column});
197-
}
198184
atDeclaration = false;
199185
previous.clear();
200186
continue;
@@ -214,10 +200,6 @@ Result scan(std::string_view text, const std::vector<std::string>& macros) {
214200
break;
215201
}
216202
const bool call = look.peek() == '(';
217-
// `suite`, or `mtest::suite` (the identifier before `::` is kept in `previous`).
218-
if (word == "suite" && (atDeclaration || previous == "mtest")) suiteState = 1;
219-
else if (suiteState == 1) suiteState = 2;
220-
else suiteState = 0;
221203
if (call && atDeclaration && std::ranges::find(macros, word) != macros.end()) {
222204
c = look;
223205
r.calls.push_back(Call{word, line, column, arguments(c)});
@@ -232,21 +214,21 @@ Result scan(std::string_view text, const std::vector<std::string>& macros) {
232214
continue;
233215
}
234216
if (ch == '{') {
235-
if (suiteState == 2) { suiteState = 3; suiteDepth = depth; }
236-
else suiteState = 0;
237217
++depth;
238218
atDeclaration = true;
239219
} else if (ch == '}') {
240220
if (depth > 0) --depth;
241-
while (!suites.empty() && suites.back().depth >= depth) suites.pop_back();
242221
atDeclaration = true;
243222
}
244-
else if (ch == ';') { atDeclaration = true; suiteState = 0; }
245-
else { atDeclaration = false; suiteState = 0; }
223+
else if (ch == ';') atDeclaration = true;
224+
else atDeclaration = false;
246225
// `std::main`, `x.main`: not the program's.
247226
if (ch != ':' ) previous.clear();
248227
c.step();
249228
}
229+
// mtest's cases as mtest reads them: its manifest is the one reader of its declarations.
230+
for (const auto& found : mcpplibs::mtest::manifest::scan(text, types))
231+
r.cases.push_back(Literal{found.id, found.line - 1, found.column - 1});
250232
return r;
251233
}
252234

‎src/server.cppm‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import mcppide.documents;
2626
import mcppide.spec;
2727
import mcppide.languageservice;
2828
import mcppide.scan;
29+
import mcpplibs.mtest.manifest;
2930
import mcppide.testing;
3031
import mcpplibs.os;
3132

3233
export namespace mcppide::server {
3334

3435
using Json = nlohmann::json;
3536

36-
inline constexpr std::string_view kVersion = "1.2.0";
37+
inline constexpr std::string_view kVersion = "1.2.1";
3738
// THE SERIES (mcpp design 2026-11-07, D15): `X.Y` of `X.Y.Z`, shared by the backend and every editor
3839
// plugin; components of one series work together, and `Z` is each component's own patch. A plugin
3940
// refuses a backend of another series, naming both versions.
@@ -1470,6 +1471,18 @@ std::optional<std::string> test_name_of(const std::filesystem::path& root, const
14701471
return below.generic_string();
14711472
}
14721473

1474+
// The suite types the project's tests declare (`class Fixture : public CTS` in a module beside them),
1475+
// read across the files of tests/ as mtest's static manifest reads them.
1476+
mcpplibs::mtest::manifest::suite_types test_suite_types(const std::filesystem::path& root) {
1477+
static const std::set<std::string> cxx{".cpp", ".cc", ".cxx", ".cppm", ".ixx", ".mpp"};
1478+
std::vector<std::string> sources;
1479+
std::error_code ec;
1480+
for (std::filesystem::recursive_directory_iterator it(root / "tests", ec), end; !ec && it != end; it.increment(ec))
1481+
if (it->is_regular_file(ec) && cxx.contains(it->path().extension().string()))
1482+
sources.push_back(read_text(it->path()));
1483+
return mcpplibs::mtest::manifest::types_of(sources);
1484+
}
1485+
14731486
// The source of a test by its name: tests/<name>.cpp (or .cc, .cxx).
14741487
std::filesystem::path test_source(const std::filesystem::path& root, std::string_view name) {
14751488
for (const auto* ext : {".cpp", ".cc", ".cxx"}) {
@@ -1492,7 +1505,7 @@ std::expected<Json, rpc::Error> Session::source_entries(const Json& p) {
14921505
if (!proj) return Json{{"file", file.generic_string()}, {"kind", "none"}};
14931506
const auto text = p.contains("text") && p["text"].is_string() ? p["text"].get<std::string>() : read_text(file);
14941507
const auto extra = test_macros();
1495-
const auto found = scan::scan(text, testing::macros(extra));
1508+
const auto found = scan::scan(text, testing::macros(extra), test_suite_types(proj->root));
14961509
Json out{{"file", file.generic_string()}, {"root", proj->root.generic_string()}, {"kind", "none"}};
14971510
if (auto name = test_name_of(proj->root, file)) {
14981511
out["kind"] = "test";
@@ -1520,7 +1533,7 @@ std::expected<Json, rpc::Error> Session::test_cases(const Json& p) {
15201533
Json out{{"root", root.generic_string()}, {"test", test}, {"file", file.generic_string()}, {"framework", nullptr}, {"cases", Json::array()}};
15211534
if (file.empty()) return out;
15221535
const auto extra = test_macros();
1523-
const auto found = scan::scan(read_text(file), testing::macros(extra));
1536+
const auto found = scan::scan(read_text(file), testing::macros(extra), test_suite_types(root));
15241537
if (found.mainLine) out["main"] = Json{{"line", *found.mainLine}, {"approximate", true}};
15251538
bool trusted;
15261539
{

‎tests/test_testing.cpp‎

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import std;
77
import mcppide.testsupport;
88
import nlohmann.json;
99
import mcppide.scan;
10+
import mcpplibs.mtest.manifest;
1011
import mcppide.testing;
1112
import mcppide.rpc;
1213
import mcppide.server;
@@ -149,31 +150,30 @@ TEST(Math,
149150
check(testing::case_outputs(fw("catch2"), "[ RUN ] x\n").empty());
150151
}
151152

152-
// mtest's cases: `"name"_test` literals, prefixed by the suites they are declared in; never a
153-
// literal in a comment or one not followed by `_test`. The framework is claimed by its package
154-
// and its cases, and a record of `mcpp test` lists and reports them (the test protocol).
153+
// mtest's cases as mtest's static manifest reads them: each object (`UTest`, `Suite`, ...) is a
154+
// case, and so is each `"name"_test` declared in one, under its name; never a literal in a
155+
// comment or one not followed by `_test`. The framework is claimed by its package and its
156+
// cases, and a record of `mcpp test` lists and reports them (the test protocol).
155157
{
156158
const auto r = scan::scan(R"(import mcpplibs.mtest;
157159
using namespace mcpplibs::mtest;
158160
// "commented"_test
159-
suite parsing{"parsing", [] {
160-
"an empty line"_test = [] { expect(true); };
161-
suite fields{"fields", [] {
162-
"one field"_test[tag{"x"}] = [] {};
163-
}};
161+
UTest empty{"an empty line", [] { expect(true); }};
162+
Suite parsing{"parsing", tag{"p"}, [] {
163+
"one field"_test[tag{"x"}] = [] {};
164164
const char* s = "not a case";
165165
}};
166-
mcpplibs::mtest::suite other{"other", [] { "after"_test = [] {}; }};
166+
mcpplibs::mtest::E2E other{"other", [] { "after"_test = [] {}; }};
167167
int main() { "top"_test = [] {}; return report(); }
168168
)", {});
169-
check(r.cases.size() == 4);
170-
check(r.cases.size() == 4 && r.cases[0].id == "parsing/an empty line" && r.cases[0].line == 4);
171-
check(r.cases.size() == 4 && r.cases[1].id == "parsing/fields/one field");
172-
check(r.cases.size() == 4 && r.cases[2].id == "other/after" && r.cases[3].id == "top");
169+
std::vector<std::string> ids;
170+
for (const auto& c : r.cases) ids.push_back(c.id);
171+
check(ids == std::vector<std::string>{"an empty line", "parsing", "parsing/one field", "other", "other/after", "top"});
172+
check(r.cases.size() == 6 && r.cases[0].line == 3 && r.cases[2].line == 5);
173173
check(testing::framework_of({"app", "mcpplibs.mtest"}, r, Json::object()) == &fw("mtest"));
174174
check(testing::framework_of({"app"}, r, Json::object()) == nullptr);
175175
const auto cases = testing::static_cases(fw("mtest"), r, Json::object());
176-
check(cases.size() == 4 && cases[0].name == "parsing/an empty line" && cases[0].line == 4);
176+
check(cases.size() == 6 && cases[0].name == "an empty line" && cases[0].line == 3);
177177

178178
const auto record = Json::parse(R"({"test":"parse","protocol":1,
179179
"listed":[{"id":"parsing/an empty line","file":"tests/parse.cpp","line":5}],
@@ -192,6 +192,19 @@ int main() { "top"_test = [] {}; return report(); }
192192
check(outcomes.size() == 4 && outcomes[3].outcome.status == "passed");
193193
}
194194

195+
// A suite type the project's tests declare in a module beside them is a suite type in every
196+
// file that uses it: the server reads the types across tests/ before it scans a file.
197+
{
198+
const std::vector<std::string> sources{
199+
"export module cts;\nimport mcpplibs.mtest;\nexport class Fixture : public mcpplibs::mtest::CTS {\n"
200+
"public:\n using CTS::CTS;\n};\n"};
201+
const auto types = mcpplibs::mtest::manifest::types_of(sources);
202+
const std::string_view cases = "import cts;\nFixture one{\"one\"};\nFixture two{\"two@warm\"};\n";
203+
const auto r = scan::scan(cases, {}, types);
204+
check(r.cases.size() == 2 && r.cases[0].id == "one" && r.cases[1].id == "two@warm" && r.cases[1].line == 2);
205+
check(scan::scan(cases, {}).cases.empty());
206+
}
207+
195208
// source/entries and test/cases over a project on disk (no mcpp: the plan's packages are not
196209
// known, so no framework is claimed, and the static entries still answer).
197210
{

0 commit comments

Comments
 (0)