ek9_add_program
Appends the program (or @Test program) to the file's 'defines program' block, created if absent, with a stub body that references every parameter and injection; answers status, edits[] and summary.
When to use it
'Add a program Main that prints X' is one call with file, name and statements:['stdout <- Stdout()', 'stdout.println(...)'] - the body included, nothing left to fill; isTest:true makes it a @Test program.
When not to use it
- Authoring any OTHER top-level construct (class/record/trait/function/component/type/constant/service) - use
ek9_new_construct. - Authoring the DI application a program binds to via 'application' - use
ek9_add_applicationfirst, then reference it here by name. - Anchoring a @Test program that ALREADY exists to a requirement - use
ek9_anchor_test(requirementId here is for a freshly-scaffolded test).
Details
parameters[].type must be one of the 18 whitelisted CLI arg types (String/Integer/Float/Boolean/Character/Bits/Date/Time/DateTime/Duration/Millisecond/Money/Colour/Resolution/Dimension/RegEx/GUID/List of String) — an invalid type (E07600), a typed primitive mixed with 'List of String' (E07610), or a program name already taken in the module all surface as would-fail from the dry-run gate. Programs may return only Integer (process exit code — E07590).
Arguments
| Argument | Type | Required | What it is |
|---|---|---|---|
application | string | Application to bind for DI — renders 'with application of <App>'. The application must resolve (define it with ek9_add_application first). | |
file | string | yes | Workspace-relative path to the .ek9 module file the program is appended to (the 'defines program' block is created if absent). For isTest:true this must be a dev source (dev/ subdirectory or QA####_dev_ file). |
injections | array of any | Components pulled from the application by injection, each ONE item as DATA - {name:'code', type:'Integer'} - never a {name} and a {type} as two items, and never with '->' or '<-' in it; the tool writes the arrows and the layout. ('code as Integer' is also accepted.) A malformed item is rejected before anything is rendered. ('logger as Logger' or 'logger as Logger!' both render 'logger as Logger!'). Each is referenced in the stub (an unused injection is E11018). | |
isTest | boolean | When true, prepend the @Test directive and emit an assert-based stub. Only legal in a dev source (E81015). | |
name | string | yes | Program name (PascalCase), e.g. 'ShowInjection' or 'GreetingTest'. |
parameters | array of any | Typed CLI argument parameters, each ONE item as DATA - {name:'code', type:'Integer'} - never a {name} and a {type} as two items, and never with '->' or '<-' in it; the tool writes the arrows and the layout. ('code as Integer' is also accepted.) A malformed item is rejected before anything is rendered. Each is referenced in the stub so it compiles (an unused arg is E08091). | |
requirementId | string | Requirement id this test anchors, e.g. 'REQ:velocity-limit' - renders '@Test: "REQ:velocity-limit"'. Requires isTest:true; supplying it for a non-test program is rejected rather than ignored. The requirement need not exist yet (writing the test first is legitimate); ek9_check_requirements reports an id that names nothing as a dangling anchor. | |
statements | array of string | The program's body, one statement or one block per entry ('stdout <- Stdout()', 'stdout.println(...)'): the program is complete in this call - no stub, no ek9_insert_statements after it. Parsed alone first; a problem names the entry and its fix. |
It also takes the arguments every tool takes.
Recorded calls
Real calls, recorded against small projects and checked on every build - a changed answer fails it. 3 of the 12 recorded are shown.
Test program non dev rejected
Request
{
"dryRun" : true,
"file" : "main.ek9",
"isTest" : true,
"name" : "BadTest"
}
Response
{
"conflicts" : [ ],
"edits" : [ ],
"error" : {
"message" : "@Test programs are only allowed in a dev source — move the target into a 'dev/' subdirectory or rename it to the QA####_dev_ pattern (E81015). Got: main.ek9"
},
"meta" : {
"serverMs" : "<timing>"
},
"status" : "error",
"summary" : "@Test programs are only allowed in a dev source — move the target into a 'dev/' subdirectory or rename it to the QA####_dev_ pattern (E81015). Got: main.ek9",
"wouldBeDiagnostics" : [ ],
"written" : false
}
Requirement without istest rejected
Request
{
"dryRun" : true,
"file" : "main.ek9",
"name" : "NotATest",
"requirementRef" : "REQ:velocity-limit"
}
Response
{
"conflicts" : [ ],
"edits" : [ ],
"error" : {
"message" : "'requirementId' anchors a @Test to a requirement, so it needs isTest: true. A plain program is an entry point and cannot anchor anything. Got: REQ:velocity-limit"
},
"meta" : {
"serverMs" : "<timing>"
},
"status" : "error",
"summary" : "'requirementId' anchors a @Test to a requirement, so it needs isTest: true. A plain program is an entry point and cannot anchor anything. Got: REQ:velocity-limit",
"wouldBeDiagnostics" : [ ],
"written" : false
}
Requirement malformed rejected
Request
{
"dryRun" : true,
"file" : "dev/tests.ek9",
"isTest" : true,
"name" : "TypoTest",
"requirementRef" : "RREQ:velocity-limit"
}
Response
{
"conflicts" : [ ],
"edits" : [ ],
"error" : {
"message" : "'RREQ:velocity-limit' is not a valid requirement id. Expected <PREFIX>:<slug> with PREFIX one of REQ, CTRL, CAP, CON and slug matching [a-z0-9-]+, e.g. 'REQ:velocity-limit'."
},
"meta" : {
"serverMs" : "<timing>"
},
"status" : "error",
"summary" : "'RREQ:velocity-limit' is not a valid requirement id. Expected <PREFIX>:<slug> with PREFIX one of REQ, CTRL, CAP, CON and slug matching [a-z0-9-]+, e.g. 'REQ:velocity-limit'.",
"wouldBeDiagnostics" : [ ],
"written" : false
}
See also
- Show me in the IDE: Your own generic class and function
- Show me in the IDE: Chapter 1: a second greeting, typed
- Show me in the IDE: Chapter 2: values, reshaped
- Show me in the IDE: Chapter 2: escapes in a string, typed
- Show me in the IDE: Chapter 2: changing a value, typed
- Show me in the IDE: Chapter 2: declaring and changing values, typed
- Show me in the IDE: Chapter 3: a three-way test, folded
- Show me in the IDE: Chapter 3: a switch, folded
- Show me in the IDE: Chapter 3: a switch of comparisons, folded
- Show me in the IDE: Chapter 3: three loops, folded
- Show me in the IDE: Chapter 3: do ... while, typed
- Show me in the IDE: Chapter 4: three pure functions, built
- Show me in the IDE: Chapter 4: a return settled by an if, built
- Show me in the IDE: Chapter 4: a function, built
- Show me in the IDE: Chapter 4: a precondition, built
- Show me in the IDE: Chapter 4: a precondition that fails, built
- Show me in the IDE: Chapter 5: tests, built
- Show me in the IDE: Chapter 7: money, typed
- Show me in the IDE: Chapter 7: dates, typed
- Show me in the IDE: Chapter 7: asking about a type
- Show me in the IDE: Chapter 7: constants, built
- Show me in the IDE: Chapter 7: a constant that is copied, built
- Show me in the IDE: Chapter 8: greeting in three languages, built
- Show me in the IDE: Chapter 8: choosing a language, built
- Show me in the IDE: Chapter 8: a language from the environment, built
- Show me in the IDE: Chapter 8: a price and a date, localised
- Show me in the IDE: Chapter 8: a text type, built
- Show me in the IDE: Chapter 9: collections, asked about
- Show me in the IDE: Chapter 9: a list, a dict and JSON
- Show me in the IDE: Chapter 9: how a collection's type is worked out
- Show me in the IDE: Chapter 9: where promotion comes from
- Show me in the IDE: Chapter 9: a collection as JSON
- Show me in the IDE: Chapter 10: guards, reshaped
- Show me in the IDE: Chapter 10: three ways to default a name, built
- Show me in the IDE: Chapter 10: safe minimum and maximum, wrapped
- Show me in the IDE: Chapter 10: a for loop that gives a value, built
- Show me in the IDE: Chapter 11: an Optional, built
- Show me in the IDE: Chapter 11: Optional and Result, built
- Show me in the IDE: Chapter 12: a pipeline, built
- Show me in the IDE: Chapter 12: a pipeline, and its tests, built
- Show me in the IDE: Chapter 13: data, an object and a function, built
- Show me in the IDE: Chapter 14: a record, built
- Show me in the IDE: Chapter 14: an enumeration, built
- Show me in the IDE: Chapter 14: what an enumeration comes with, built
- Show me in the IDE: Chapter 15: a range and a pattern, built
- Show me in the IDE: Chapter 15: a constrained type, built
- Show me in the IDE: Chapter 15: promoting a constrained type, built
- Show me in the IDE: Chapter 15: stepping a constrained type, built
- Show me in the IDE: Chapter 16: a class, built
- Show me in the IDE: Chapter 16: a class that hands out a copy, built
- Show me in the IDE: Chapter 16: a class that needs an owner, built
- Show me in the IDE: Chapter 17: an abstract type and its subtypes, built
- Show me in the IDE: Chapter 17: a family of records, built
- Show me in the IDE: Chapter 18: traits that build on a trait, built
- Show me in the IDE: Chapter 18: traits and delegation, built
- Show me in the IDE: Chapter 18: two traits, one method, built
- Show me in the IDE: Chapter 18: a sealed family, built
- Show me in the IDE: Chapter 19: a component, built
- Show me in the IDE: Chapter 20: a generic type, read
- Show me in the IDE: Chapter 21: operators, built
- Show me in the IDE: Chapter 21: every other operator, in one step
- Show me in the IDE: Chapter 21: promotion, #^
- Show me in the IDE: Chapter 22: a notes-keeper with options, built
- Show me in the IDE: Chapter 22: a program with arguments, built
- Show me in the IDE: Chapter 23: the game, built and played
- Show me in the IDE: Chapter 24: settings, an Optional and a Result, built
- Show me in the IDE: Chapter 24: the third safe container, built
- Show me in the IDE: Chapter 24: the four states of a Result, built
- Show me in the IDE: Chapter 24: what keeps the proof, built
- Show me in the IDE: Chapter 25: one split, + and +=, built
- Show me in the IDE: Chapter 25: what pure promises, built
- Show me in the IDE: Chapter 25: copy, merge and replace, built
- Show me in the IDE: Chapter 25: one object, two names, built
- Show me in the IDE: Chapter 25: a copy that shares, built
- Show me in the IDE: Chapter 25: the re-point head, built
- Show me in the IDE: Chapter 26: nine pure shapes, built
- Show me in the IDE: Chapter 26: the impure twins, built
- Show me in the IDE: Chapter 26: your own function type, built
- Show me in the IDE: Chapter 26: an abstract function as a contract, built
- Show me in the IDE: Chapter 28: one data set, every verb, built
- Show me in the IDE: Chapter 28: replace or append, built
- Show me in the IDE: Chapter 28: JSON as a sink, built
- Show me in the IDE: Chapter 28: async is a stage, built
- Show me in the IDE: Chapter 29: the parent's version on purpose, built
- Show me in the IDE: Chapter 30: a generic cache over two types, built
- Show me in the IDE: Chapter 30: a generic constrained by a trait, built
- Show me in the IDE: Chapter 30: the copy a generic asks every T for, built
- Show me in the IDE: Chapter 30: a generic function and a function type, built
- Show me in the IDE: Chapter 30: a range over a type parameter, built
- Show me in the IDE: Chapter 30: a constrained type over a record, built
- Show me in the IDE: Chapter 31: a project of several files and two modules, built
- Show me in the IDE: Chapter 31: the four comment forms, built
- Show me in the IDE: Chapter 32: an exception hierarchy and its dispatcher, built
- Show me in the IDE: Chapter 32: a catch that names its type, built
- Show me in the IDE: Chapter 32: try as an expression, built
- Show me in the IDE: Chapter 32: when a resource closes, built
- Show me in the IDE: Chapter 32: a holder that closes what it holds, built
- Show me in the IDE: Chapter 32: a close that fails, built
- Show me in the IDE: Chapter 32: the Panic a catch cannot see, built
- Show me in the IDE: Chapter 32: an exception that ends the program, built
- Show me in the IDE: Chapter 32: a program that returns its exit status, built
- Show me in the IDE: Chapter 32: exceptions inside a pipeline, built
- Show me in the IDE: Chapter 33: one lock over one record, built
- Show me in the IDE: Chapter 33: workers that share nothing, built
- Show me in the IDE: Chapter 33: the answer a key would lose, built
- Show me in the IDE: Chapter 33: two locks, one order, built
- Show me in the IDE: Chapter 33: one lock, nothing to order, built
- Show me in the IDE: Chapter 33: the pair no lock can make atomic, built
- Show me in the IDE: Chapter 34: a contract, two implementations and two applications, built
- Show me in the IDE: Chapter 34: the seams that make a game testable, built
- Show me in the IDE: Chapter 35: two aspects on one component, built
- Show me in the IDE: Chapter 35: a timing aspect and its own data, built
- Show me in the IDE: Chapter 35: an aspect around a method that throws, built
- Show me in the IDE: Chapter 35: an aspect that counts calls, built
- Show me in the IDE: Chapter 36: a server and its own client in one process, built
- Show me in the IDE: Chapter 36: a TCP line server and its client, built
- Show me in the IDE: Chapter 36: a UDP echo server and client, built
- Show me in the IDE: Chapter 36: UDP as a stream pipeline, built
- Show me in the IDE: Chapter 36: where a program's URLs come from, built
- Show me in the IDE: Chapter 36: links from a base URL, built
- Show me in the IDE: Chapter 36: a service and its HTTP client in one process, built
- Show me in the IDE: Chapter 37: the smallest web service, built
- Show me in the IDE: Chapter 37: JSON in and out, built
- Show me in the IDE: Chapter 37: two routes that could both match, built
- Show me in the IDE: Chapter 37: a key that cannot be printed, built
- Show me in the IDE: Chapter 37: a status decided late, built
- Show me in the IDE: Chapter 38: a package to share, built and packaged
- Show me in the IDE: Chapter 38: declaring what a package may do, built
- Show me in the IDE: Chapter 38: a library to depend on, built and installed
- Show me in the IDE: Chapter 39: three kinds of test, one runner, built
- Show me in the IDE: Chapter 40: what coverage cannot say, built
- Show me in the IDE: Chapter 41: substitution, as the compiler checks it, built
- Show me in the IDE: Chapter 41: the tri-state operators, built
- Show me in the IDE: Appendix: a literal of every type, built
- Show me in the IDE: An application and its test double
- Show me in the IDE: An aspect around a component
- Show me in the IDE: A web service, built and served
- Show me in the IDE: A TCP echo on localhost