summary refs log tree commit diff stats
path: root/tests/nimdoc
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-05-20 00:45:34 -0700
committerGitHub <noreply@github.com>2020-05-20 09:45:34 +0200
commit3d20f141939b0cb76079a9b0ae7784f7877f1698 (patch)
treeff6c7b9943309b0df409be3c15143ffad56b0e9f /tests/nimdoc
parent4ae341353de5c58dc339e47b0eec2bbb4649dc10 (diff)
downloadNim-3d20f141939b0cb76079a9b0ae7784f7877f1698.tar.gz
fix #10731 ; `runnableExamples "-b:cpp --run:off": code` works (#14384)
* runnableExamples "-b:cpp -r:off": code
Diffstat (limited to 'tests/nimdoc')
-rw-r--r--tests/nimdoc/trunnableexamples.nim35
1 files changed, 34 insertions, 1 deletions
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: "<exception>".} = 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: