{"record":{"id":"562448efd2b9ba24","repo":"apple/pkl","slug":"usage-pkl-test-options-modules-error-m","errorCode":null,"errorMessage":"Usage: pkl test [<options>] <modules>...\n\nError: missing argument <modules>","messagePattern":"Usage: pkl test \\[<options>\\] <modules>\\.\\.\\.\n\nError: missing argument <modules>","errorType":"exception","errorClass":"CliException","httpStatus":null,"severity":"error","filePath":"pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt","lineNumber":55,"sourceCode":"  private val errWriter: Writer = System.err.writer(),\n) : CliCommand(options) {\n\n  override fun doRun() {\n    val builder = evaluatorBuilder()\n    try {\n      evalTest(builder)\n    } finally {\n      Closeables.closeQuietly(builder.moduleKeyFactories)\n      Closeables.closeQuietly(builder.resourceReaders)\n    }\n  }\n\n  private fun evalTest(builder: EvaluatorBuilder) {\n    val sources =\n      options.normalizedSourceModules.ifEmpty { project?.tests?.map { it.toUri() } }\n        ?:\n        // keep in sync with error message thrown by clikt\n        throw CliException(\n          \"\"\"\n          Usage: pkl test [<options>] <modules>...\n\n          Error: missing argument <modules>\n          \"\"\"\n            .trimIndent()\n        )\n\n    val evaluator = builder.build()\n    evaluator.use {\n      var failed = false\n      var isExampleWrittenFailure = true\n      val moduleNames = mutableSetOf<String>()\n      val reporter =\n        when (testOptions.reporter) {\n          TestReporter.SPEC -> SpecReporter(useColor)\n          TestReporter.MINIMAL -> MinimalReporter(useColor)\n        }","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/apple/pkl/blob/f3efcbfc9b60d30053b0536d664948d7aa1b8673/pkl-cli/src/main/kotlin/org/pkl/cli/CliTestRunner.kt#L37-L73","documentation":"`pkl test` requires test modules to run. If no modules were given on the command line and the project (PklProject) does not declare any `tests` entries, CliTestRunner.evalTest throws this CliException mimicking clikt's missing-argument error. It exists because modules can come either from CLI args or project config, which clikt cannot validate on its own.","triggerScenarios":"Running `pkl test` with zero positional <modules> arguments while the current project's `tests` list in PklProject is empty or absent.","commonSituations":"Developer runs `pkl test` at a directory without a PklProject defining tests, expecting auto-discovery; CI script dropped the module arguments; project migrated and the `tests` block was removed from PklProject.","solutions":["Pass test modules explicitly: `pkl test myTests.pkl` (or multiple modules).","Declare tests in PklProject under `tests: { ... }` so bare `pkl test` has modules to run.","Run from the project root (where PklProject lives) so project.tests is picked up."],"exampleFix":"# before\n$ pkl test\nError: missing argument <modules>\n\n# after (option 1)\n$ pkl test tests/myTests.pkl\n\n# after (option 2: PklProject.pkl)\ntests {\n  \"tests/myTests.pkl\"\n}","handlingStrategy":"validation","validationCode":"# before running pkl test, ensure modules exist either on CLI or in project\nif [ -z \"$MODULES\" ] && ! grep -q 'tests' PklProject.pkl; then\n  echo \"error: no test modules given and PklProject declares no tests\" >&2; exit 2\nfi\npkl test $MODULES","typeGuard":null,"tryCatchPattern":"// pkl test exits non-zero with this message; check exit code in scripts\npkl test \"$@\" || { echo \"pkl test: supply <modules> or declare tests in PklProject\"; exit 1; }","preventionTips":["Always declare `tests` in PklProject.pkl so bare `pkl test` works.","In CI, pass explicit module paths rather than relying on ambient project config.","Run from the project root so PklProject is discovered."],"tags":["cli","missing-argument","testing"],"backgroundTag":"missing-cli-argument","analyzedSha":"f3efcbfc9b60d30053b0536d664948d7aa1b8673","analyzedAt":"2026-09-08T13:10:45.570Z","contentChangedAt":"2026-09-08T13:10:45.570Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}