From 3d20f141939b0cb76079a9b0ae7784f7877f1698 Mon Sep 17 00:00:00 2001 From: Timothee Cour Date: Wed, 20 May 2020 00:45:34 -0700 Subject: fix #10731 ; `runnableExamples "-b:cpp --run:off": code` works (#14384) * runnableExamples "-b:cpp -r:off": code --- tests/nimdoc/trunnableexamples.nim | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/nimdoc/trunnableexamples.nim b/tests/nimdoc/trunnableexamples.nim index e3ae6b9cb..73cfacd43 100644 --- a/tests/nimdoc/trunnableexamples.nim +++ b/tests/nimdoc/trunnableexamples.nim @@ -1,5 +1,5 @@ discard """ -cmd: "nim doc $file" +cmd: "nim doc --doccmd:-d:testFooExternal --hints:off $file" action: "compile" nimout: ''' foo1 @@ -66,6 +66,39 @@ when true: # issue #12746 # specifying Error is culprit discard +when true: # runnableExamples with rdoccmd + runnableExamples "-d:testFoo -d:testBar": + doAssert defined(testFoo) and defined(testBar) + doAssert defined(testFooExternal) + runnableExamples "-d:testFoo2": + doAssert defined(testFoo2) + doAssert not defined(testFoo) # doesn't get confused by other examples + + ## all these syntaxes work too + runnableExamples("-d:testFoo2"): discard + runnableExamples(): discard + runnableExamples: discard + runnableExamples "-r:off": # issue #10731 + doAssert false ## we compile only (-r:off), so this won't be run + runnableExamples "-b:js": + import std/compilesettings + proc startsWith*(s, prefix: cstring): bool {.noSideEffect, importjs: "#.startsWith(#)".} + doAssert querySetting(backend) == "js" + runnableExamples "-b:cpp": + static: doAssert defined(cpp) + type std_exception {.importcpp: "std::exception", header: "".} = object + + proc fun2*() = + runnableExamples "-d:foo": discard # checks that it also works inside procs + + when false: # future work + # passing non-string-litterals (for reuse) + const a = "-b:cpp" + runnableExamples(a): discard + + # passing seq (to run with multiple compilation options) + runnableExamples(@["-b:cpp", "-b:js"]): discard + # also check for runnableExamples at module scope runnableExamples: block: -- cgit 1.4.1-2-gfad0