Bug 21461 – unittests with scope

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-12-08T15:06:48Z
Last change time
2024-12-13T19:13:21Z
Assigned to
No Owner
Creator
Bolpat
Moved to GitHub: dmd#18007 →

Comments

Comment #0 by qs.il.paperinik — 2020-12-08T15:06:48Z
CONTEXT: Unit tests are an imperative scope, i.e. consist of statements to be executed in order. Sometimes unit tests need declarative spaces that consist of declarations. As an example, in imperative scopes, one cannot overload functions. Unless specified with `static`, functions and aggregate types declared in an imperative scope have a context pointer. PROBLEM: To understand documentation examples generated by unit tests, one needs to have an unnecessary deep understanding of the aforementioned rules and probably more to abstract from the test. PROPOSAL: An enhancement would be to give unit tests an optional declarative scope that introduces declarations for that unit test. Documentation generators should display these declarations as build-up for the example. A documentation example created from a unit test with declarative scope would look like this: Example: ...descriptive text... Consider <code> // declarations </code> then <code> // unit test code </code> That way, especially for a beginner, it is clear what goes to a declarative context and what goes to a function a programmer would write. The syntax could be similar to `in` and `out` contracts. Keyword could be `scope`. unittest scope { // decls } do { // tests } This is lowered to version(unittest) private struct __ImplDefined { private static: // decls unittest { // tests } } That way, the unit test has access to the declarations and the declarations are considered "nearer" (in scope terms) than symbols in the module.
Comment #1 by robert.schadek — 2024-12-13T19:13:21Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18007 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB