From dd6b0f81efe54cbc17a79e5c3d7aa7aaf34357f6 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Mon, 1 Mar 2021 05:26:39 -0800 Subject: [PATCH] use `-r:off` for runnableExamples that should compile but not run (#17203) * use -r:off for runnableExamples that should compile but not run * use -r:off in other RT disabled tests --- lib/impure/rdstdin.nim | 17 ++++++------ lib/pure/asynchttpserver.nim | 40 +++++++++++++--------------- lib/pure/oids.nim | 4 +-- lib/pure/sugar.nim | 4 +-- lib/wrappers/linenoise/linenoise.nim | 15 +++++------ 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/lib/impure/rdstdin.nim b/lib/impure/rdstdin.nim index 362d71b375..c580b89d1f 100644 --- a/lib/impure/rdstdin.nim +++ b/lib/impure/rdstdin.nim @@ -13,15 +13,14 @@ ## is used. This suffices because Windows' console already provides the ## wanted functionality. -runnableExamples: - if false: - echo readLineFromStdin("Is Nim awesome? (Y/n): ") - var line: string - while true: - let ok = readLineFromStdin("How are you? ", line) - if not ok: break # ctrl-C or ctrl-D will cause a break - if line.len > 0: echo line - echo "exiting" +runnableExamples("-r:off"): + echo readLineFromStdin("Is Nim awesome? (Y/n): ") + var line: string + while true: + let ok = readLineFromStdin("How are you? ", line) + if not ok: break # ctrl-C or ctrl-D will cause a break + if line.len > 0: echo line + echo "exiting" when defined(windows): proc readLineFromStdin*(prompt: string): string {. diff --git a/lib/pure/asynchttpserver.nim b/lib/pure/asynchttpserver.nim index f5baf15172..38be4ceac6 100644 --- a/lib/pure/asynchttpserver.nim +++ b/lib/pure/asynchttpserver.nim @@ -14,32 +14,30 @@ ## application in production you should use a reverse proxy (for example nginx) ## instead of allowing users to connect directly to this server. -runnableExamples: +runnableExamples("-r:off"): # This example will create an HTTP server on port 8080. The server will # respond to all requests with a `200 OK` response code and "Hello World" - # as the response body. Run locally with: - # `nim doc --doccmd:-d:nimAsyncHttpServerEnableTest --lib:lib lib/pure/asynchttpserver.nim` + # as the response body. import std/asyncdispatch - if defined(nimAsyncHttpServerEnableTest): - proc main {.async.} = - const port = 8080 - var server = newAsyncHttpServer() - proc cb(req: Request) {.async.} = - echo (req.reqMethod, req.url, req.headers) - let headers = {"Content-type": "text/plain; charset=utf-8"} - await req.respond(Http200, "Hello World", headers.newHttpHeaders()) + proc main {.async.} = + const port = 8080 + var server = newAsyncHttpServer() + proc cb(req: Request) {.async.} = + echo (req.reqMethod, req.url, req.headers) + let headers = {"Content-type": "text/plain; charset=utf-8"} + await req.respond(Http200, "Hello World", headers.newHttpHeaders()) - echo "test this with: curl localhost:" & $port & "/" - server.listen(Port(port)) - while true: - if server.shouldAcceptRequest(): - await server.acceptRequest(cb) - else: - # too many concurrent connections, `maxFDs` exceeded - # wait 500ms for FDs to be closed - await sleepAsync(500) + echo "test this with: curl localhost:" & $port & "/" + server.listen(Port(port)) + while true: + if server.shouldAcceptRequest(): + await server.acceptRequest(cb) + else: + # too many concurrent connections, `maxFDs` exceeded + # wait 500ms for FDs to be closed + await sleepAsync(500) - waitFor main() + waitFor main() import asyncnet, asyncdispatch, parseutils, uri, strutils import httpcore diff --git a/lib/pure/oids.nim b/lib/pure/oids.nim index 967c4901b3..fb70047b6d 100644 --- a/lib/pure/oids.nim +++ b/lib/pure/oids.nim @@ -100,8 +100,8 @@ proc genOid*(): Oid = ## Generates a new OID. runnableExamples: doAssert ($genOid()).len == 24 - if false: doAssert $genOid() == "5fc7f546ddbbc84800006aaf" - + runnableExamples("-r:off"): + echo $genOid() # for example, "5fc7f546ddbbc84800006aaf" genOid(result, incr, fuzz) proc generatedTime*(oid: Oid): Time = diff --git a/lib/pure/sugar.nim b/lib/pure/sugar.nim index ccad5cd853..8d23696acc 100644 --- a/lib/pure/sugar.nim +++ b/lib/pure/sugar.nim @@ -168,11 +168,11 @@ macro dump*(x: untyped): untyped = ## See also: `dumpToString` which is more convenient and useful since ## it expands intermediate templates/macros, returns a string instead of ## calling `echo`, and works with statements and expressions. - runnableExamples: + runnableExamples("-r:off"): let x = 10 y = 20 - if false: dump(x + y) # if true would print `x + y = 30` + dump(x + y) # prints: `x + y = 30` let s = x.toStrLit result = quote do: diff --git a/lib/wrappers/linenoise/linenoise.nim b/lib/wrappers/linenoise/linenoise.nim index 3bfd74586d..c9f1dd6956 100644 --- a/lib/wrappers/linenoise/linenoise.nim +++ b/lib/wrappers/linenoise/linenoise.nim @@ -58,14 +58,13 @@ when defined nimExperimentalLinenoiseExtra: ## line editing API that allows returning the line entered and an indicator ## of which control key was entered, allowing user to distinguish between ## for example ctrl-C vs ctrl-D. - runnableExamples("-d:nimExperimentalLinenoiseExtra"): - if false: - var ret: ReadLineResult - while true: - readLineStatus("name: ", ret) # ctrl-D will exit, ctrl-C will go to next prompt - if ret.line.len > 0: echo ret.line - if ret.status == lnCtrlD: break - echo "exiting" + runnableExamples("-d:nimExperimentalLinenoiseExtra -r:off"): + var ret: ReadLineResult + while true: + readLineStatus("name: ", ret) # ctrl-D will exit, ctrl-C will go to next prompt + if ret.line.len > 0: echo ret.line + if ret.status == lnCtrlD: break + echo "exiting" var data: linenoiseData let buf = linenoiseExtra(prompt, data.addr) result.line = $buf