diff options
Diffstat (limited to 'tests/modules')
55 files changed, 352 insertions, 24 deletions
diff --git a/tests/modules/UpperCased.nim b/tests/modules/UpperCased.nim new file mode 100644 index 000000000..7beffcc5f --- /dev/null +++ b/tests/modules/UpperCased.nim @@ -0,0 +1,6 @@ + +# bug #5076 + +var str*: string + +UpperCased.str = "hello" diff --git a/tests/modules/a/module_name_clashes.nim b/tests/modules/a/module_name_clashes.nim new file mode 100644 index 000000000..209526e22 --- /dev/null +++ b/tests/modules/a/module_name_clashes.nim @@ -0,0 +1,8 @@ +# See `tmodule_name_clashes` + +import ../b/module_name_clashes +type A* = object + b*: B + +proc print*(a: A) = + echo repr a diff --git a/tests/modules/a/utils.nim b/tests/modules/a/utils.nim new file mode 100644 index 000000000..f37abfb93 --- /dev/null +++ b/tests/modules/a/utils.nim @@ -0,0 +1,2 @@ +proc burnMem*(a: int) = + discard diff --git a/tests/modules/b/module_name_clashes.nim b/tests/modules/b/module_name_clashes.nim new file mode 100644 index 000000000..6a10cac33 --- /dev/null +++ b/tests/modules/b/module_name_clashes.nim @@ -0,0 +1,3 @@ +# See `tmodule_name_clashes` + +type B* = object diff --git a/tests/modules/b/utils.nim b/tests/modules/b/utils.nim new file mode 100644 index 000000000..e343385f5 --- /dev/null +++ b/tests/modules/b/utils.nim @@ -0,0 +1,2 @@ +# module b/utils.nim +let x* = 10 diff --git a/tests/modules/definitions.nim b/tests/modules/definitions.nim new file mode 100644 index 000000000..edc6eaa6d --- /dev/null +++ b/tests/modules/definitions.nim @@ -0,0 +1,4 @@ +var v*: int +proc p* = echo "proc p called" +template t* = echo "template t expanded" + diff --git a/tests/modules/m9627/a.nim b/tests/modules/m9627/a.nim new file mode 100644 index 000000000..0dd32430e --- /dev/null +++ b/tests/modules/m9627/a.nim @@ -0,0 +1 @@ +var a = 10 diff --git a/tests/modules/m9627/b.nim b/tests/modules/m9627/b.nim new file mode 100644 index 000000000..2806a78ed --- /dev/null +++ b/tests/modules/m9627/b.nim @@ -0,0 +1 @@ +var b = 9 diff --git a/tests/modules/mforwarded_pure_enum.nim b/tests/modules/mforwarded_pure_enum.nim new file mode 100644 index 000000000..3f03390a5 --- /dev/null +++ b/tests/modules/mforwarded_pure_enum.nim @@ -0,0 +1,3 @@ + +import mforwarded_pure_enum2 +export mforwarded_pure_enum2.PureEnum diff --git a/tests/modules/mforwarded_pure_enum2.nim b/tests/modules/mforwarded_pure_enum2.nim new file mode 100644 index 000000000..e5d5d2a71 --- /dev/null +++ b/tests/modules/mforwarded_pure_enum2.nim @@ -0,0 +1,4 @@ + +type + PureEnum* {.pure.} = enum + x, y, z diff --git a/tests/modules/mimport_in_config.nim b/tests/modules/mimport_in_config.nim new file mode 100644 index 000000000..555b6074d --- /dev/null +++ b/tests/modules/mimport_in_config.nim @@ -0,0 +1,2 @@ +type + DefinedInB* = int diff --git a/tests/modules/mincludeprefix.nim b/tests/modules/mincludeprefix.nim new file mode 100644 index 000000000..6d557a430 --- /dev/null +++ b/tests/modules/mincludeprefix.nim @@ -0,0 +1 @@ +const bar = 456 diff --git a/tests/modules/mincludetemplate.nim b/tests/modules/mincludetemplate.nim new file mode 100644 index 000000000..febe9bfcf --- /dev/null +++ b/tests/modules/mincludetemplate.nim @@ -0,0 +1 @@ +const foo = 123 diff --git a/tests/modules/mmodule_same_proc.nim b/tests/modules/mmodule_same_proc.nim new file mode 100644 index 000000000..5ce56ec11 --- /dev/null +++ b/tests/modules/mmodule_same_proc.nim @@ -0,0 +1,6 @@ + +# the module being the same name as the proc +# is a requirement to trigger the error +import mmodule_same_proc_client + +proc bar*[T](foo: T): bool = foo.mmodule_same_proc_client() diff --git a/tests/modules/mmodule_same_proc_client.nim b/tests/modules/mmodule_same_proc_client.nim new file mode 100644 index 000000000..e36ec42cf --- /dev/null +++ b/tests/modules/mmodule_same_proc_client.nim @@ -0,0 +1,2 @@ + +proc mmodule_same_proc_client*(x: string): bool = x.len > 0 diff --git a/tests/modules/mnotuniquename.nim b/tests/modules/mnotuniquename.nim new file mode 100644 index 000000000..54d5883cd --- /dev/null +++ b/tests/modules/mnotuniquename.nim @@ -0,0 +1 @@ +proc flat*() = echo "flat" diff --git a/tests/modules/morder_depa.nim b/tests/modules/morder_depa.nim new file mode 100644 index 000000000..846fb1441 --- /dev/null +++ b/tests/modules/morder_depa.nim @@ -0,0 +1,5 @@ + +import morder_depb + +proc Foo*(x: int): Foo = discard + diff --git a/tests/modules/morder_depb.nim b/tests/modules/morder_depb.nim new file mode 100644 index 000000000..b77bc5acb --- /dev/null +++ b/tests/modules/morder_depb.nim @@ -0,0 +1 @@ +type Foo* = array[2, byte] diff --git a/tests/modules/mrange.nim b/tests/modules/mrange.nim new file mode 100644 index 000000000..20c424a8c --- /dev/null +++ b/tests/modules/mrange.nim @@ -0,0 +1,5 @@ + +proc range*() = echo "yo" + +proc set*(a: int) = + discard diff --git a/tests/modules/proxy_module.nim b/tests/modules/proxy_module.nim new file mode 100644 index 000000000..c244688cd --- /dev/null +++ b/tests/modules/proxy_module.nim @@ -0,0 +1,3 @@ +import definitions +export definitions except p + diff --git a/tests/modules/seq.nim b/tests/modules/seq.nim new file mode 100644 index 000000000..176e44025 --- /dev/null +++ b/tests/modules/seq.nim @@ -0,0 +1,5 @@ +var seq: seq[int] +var b: seq[float] + +echo seq +echo b diff --git a/tests/modules/t8665.nim b/tests/modules/t8665.nim new file mode 100644 index 000000000..74d31452f --- /dev/null +++ b/tests/modules/t8665.nim @@ -0,0 +1,5 @@ +discard """ + action: compile +""" + +import treorder diff --git a/tests/modules/t9627.nim b/tests/modules/t9627.nim new file mode 100644 index 000000000..daba46374 --- /dev/null +++ b/tests/modules/t9627.nim @@ -0,0 +1,7 @@ +discard """ + output: "109" +""" + +include m9627 / [a, b] + +echo a, b diff --git a/tests/modules/tambig_range.nim b/tests/modules/tambig_range.nim new file mode 100644 index 000000000..e1ecc0013 --- /dev/null +++ b/tests/modules/tambig_range.nim @@ -0,0 +1,13 @@ +discard """ + errormsg: "ambiguous identifier: 'range' -- use one of the following:" + line: "13" +""" + +import mrange + +# bug #6965 +type SomeObj = object + s: set[int8] + +# bug #6726 +range() diff --git a/tests/modules/tcanimport.nim b/tests/modules/tcanimport.nim new file mode 100644 index 000000000..bc4e2e53f --- /dev/null +++ b/tests/modules/tcanimport.nim @@ -0,0 +1,19 @@ +discard """ + output: '''ABC +nope''' +""" + +template canImport(x): bool = + compiles: + import x + +when canImport(strutils): + import strutils + echo "abc".toUpperAscii +else: + echo "meh" + +when canImport(none): + echo "what" +else: + echo "nope" diff --git a/tests/modules/texplicit_system_import.nim b/tests/modules/texplicit_system_import.nim index bc4d018bf..0a4cedc71 100644 --- a/tests/modules/texplicit_system_import.nim +++ b/tests/modules/texplicit_system_import.nim @@ -1,9 +1,9 @@ -##. import system except `+` + discard """ errormsg: "undeclared identifier: '+'" line: 9 """ -# Testament requires that the initial """ occurs before the 40th byte -# in the file. No kidding... + + echo 4+5 diff --git a/tests/modules/texport2.nim b/tests/modules/texport2.nim index 6e55873c5..e90c58673 100644 --- a/tests/modules/texport2.nim +++ b/tests/modules/texport2.nim @@ -1,9 +1,16 @@ +discard """ +output: ''' +abc +xyz +B.foo +''' +""" + # bug #1595, #1612 import mexport2a proc main() = - echo "Import Test, two lines should follow. One with abc and one with xyz." printAbc() printXyz() diff --git a/tests/modules/tfowarded_pure_enum.nim b/tests/modules/tfowarded_pure_enum.nim new file mode 100644 index 000000000..1d2c4f342 --- /dev/null +++ b/tests/modules/tfowarded_pure_enum.nim @@ -0,0 +1,7 @@ +discard """ + output: '''z''' +""" + +import mforwarded_pure_enum as t2 + +echo z diff --git a/tests/modules/timport_in_config.nim b/tests/modules/timport_in_config.nim new file mode 100644 index 000000000..847b063bd --- /dev/null +++ b/tests/modules/timport_in_config.nim @@ -0,0 +1,9 @@ +discard """ +output: '''hallo''' +joinable: false +""" + +# bug #9978, #9994 +var x: DefinedInB + +echo "hi".replace("i", "allo") diff --git a/tests/modules/timport_in_config.nim.cfg b/tests/modules/timport_in_config.nim.cfg new file mode 100644 index 000000000..2633e1012 --- /dev/null +++ b/tests/modules/timport_in_config.nim.cfg @@ -0,0 +1,2 @@ +--import: "strutils" +--import: "mimport_in_config" diff --git a/tests/modules/timportas.nim b/tests/modules/timportas.nim new file mode 100644 index 000000000..179613c6b --- /dev/null +++ b/tests/modules/timportas.nim @@ -0,0 +1,21 @@ +discard """ + action: run +""" + +import .. / modules / [mexporta as a1, definitions as foo1] +import .. / modules / definitions as foo2 +import ./[mexporta as a2, definitions as foo3] +import std / times as bar +from times as bar2 import nil +import times as bar3 except convert +import definitions as baz + +discard foo1.v +discard foo2.v +discard foo3.v +discard bar.now() +discard bar2.now() +discard bar3.now() +discard baz.v +discard a1.xyz +discard a2.xyz diff --git a/tests/modules/timportexcept.nim b/tests/modules/timportexcept.nim index 93a7fd642..40b748088 100644 --- a/tests/modules/timportexcept.nim +++ b/tests/modules/timportexcept.nim @@ -1,10 +1,9 @@ discard """ - line: 9 errormsg: "undeclared identifier: '%'" + line: 9 """ import strutils except `%` # doesn't work echo "$1" % "abc" - diff --git a/tests/modules/tincludeas.nim b/tests/modules/tincludeas.nim new file mode 100644 index 000000000..b82e38b14 --- /dev/null +++ b/tests/modules/tincludeas.nim @@ -0,0 +1,6 @@ +discard """ + errormsg: "Cannot use 'as' in 'include'." + line: 6 +""" + +include foobar as foo diff --git a/tests/modules/tincludeprefix.nim b/tests/modules/tincludeprefix.nim new file mode 100644 index 000000000..d45a6eff3 --- /dev/null +++ b/tests/modules/tincludeprefix.nim @@ -0,0 +1,3 @@ +include ./[mincludeprefix, mincludetemplate] +doAssert foo == 123 +doAssert bar == 456 diff --git a/tests/modules/tincludetemplate.nim b/tests/modules/tincludetemplate.nim new file mode 100644 index 000000000..77e409ee5 --- /dev/null +++ b/tests/modules/tincludetemplate.nim @@ -0,0 +1,5 @@ +# issue #12539 + +template includePath(n: untyped) = include ../modules/n # But `include n` works +includePath(mincludetemplate) +doAssert foo == 123 diff --git a/tests/modules/tmismatchedvisibility.nim b/tests/modules/tmismatchedvisibility.nim index 325c729c0..b649a5a3e 100644 --- a/tests/modules/tmismatchedvisibility.nim +++ b/tests/modules/tmismatchedvisibility.nim @@ -1,6 +1,6 @@ discard """ + errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)' has non-public forward declaration at " line: 8 - errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)' has non-public forward declaration in " """ proc foo(a: int): int diff --git a/tests/modules/tmodule_name_clashes.nim b/tests/modules/tmodule_name_clashes.nim new file mode 100644 index 000000000..814d5d152 --- /dev/null +++ b/tests/modules/tmodule_name_clashes.nim @@ -0,0 +1,17 @@ +discard """ +matrix: "--mm:refc" +targets: "c" +ccodecheck: "\\i @('atmaatsmodule_name_clashesdotnim_DatInit000')" +ccodecheck: "\\i @('atmbatsmodule_name_clashesdotnim_DatInit000')" +joinable: false +""" + +# Test module name clashes within same package. +# This was created to test that module symbol mangling functioned correctly +# for the C backend when there are one or more modules with the same name in +# a package, and more than one of them require module initialization procs. +# I'm not sure of the simplest method to cause the init procs to be generated. + +import a/module_name_clashes + +print A() diff --git a/tests/modules/tmodule_same_proc.nim b/tests/modules/tmodule_same_proc.nim new file mode 100644 index 000000000..dc4dfd3d6 --- /dev/null +++ b/tests/modules/tmodule_same_proc.nim @@ -0,0 +1,9 @@ + +import mmodule_same_proc + +# importing baz causes the error not to trigger +#import baz + +# bug #11188 + +discard "foo".bar() diff --git a/tests/modules/tmodulesymtype.nim b/tests/modules/tmodulesymtype.nim new file mode 100644 index 000000000..d17c4cca4 --- /dev/null +++ b/tests/modules/tmodulesymtype.nim @@ -0,0 +1,22 @@ +discard """ +cmd: "nim check $file" +""" + +# bug #19225 +import std/sequtils +sequtils #[tt.Error +^ expression has no type: sequtils]# +proc foo() = + block: #[tt.Error + ^ expression has no type: block: + sequtils]# + sequtils + +foo() + +# issue #23399 +when isMainModule: + sequtils #[tt.Error + ^ expression has no type: sequtils]# + +discard diff --git a/tests/modules/tnamspc.nim b/tests/modules/tnamspc.nim index 2f488644c..93ce71568 100644 --- a/tests/modules/tnamspc.nim +++ b/tests/modules/tnamspc.nim @@ -1,12 +1,10 @@ discard """ + errormsg: "undeclared identifier: \'global\'" file: "tnamspc.nim" line: 10 - errormsg: "undeclared identifier: \'global\'" """ # Test17 - test correct handling of namespaces import mnamspc1 global = 9 #ERROR - - diff --git a/tests/modules/tnotuniquename.nim b/tests/modules/tnotuniquename.nim new file mode 100644 index 000000000..bc401e662 --- /dev/null +++ b/tests/modules/tnotuniquename.nim @@ -0,0 +1,10 @@ +discard """ + output: '''nested +flat''' +""" + +import mnotuniquename +import tnotuniquename_dir/mnotuniquename as nun + +nested() +flat() diff --git a/tests/modules/tnotuniquename2.nim b/tests/modules/tnotuniquename2.nim new file mode 100644 index 000000000..e4501bc24 --- /dev/null +++ b/tests/modules/tnotuniquename2.nim @@ -0,0 +1,8 @@ +discard """ + errormsg: "module names need to be unique per Nimble package" + file: "tnotuniquename/mnotuniquename.nim" + disabled: "true" +""" + +import mnotuniquename +import tnotuniquename/mnotuniquename diff --git a/tests/modules/tnotuniquename_dir/mnotuniquename.nim b/tests/modules/tnotuniquename_dir/mnotuniquename.nim new file mode 100644 index 000000000..11e52d9d0 --- /dev/null +++ b/tests/modules/tnotuniquename_dir/mnotuniquename.nim @@ -0,0 +1,2 @@ + +proc nested*() = echo "nested" diff --git a/tests/modules/topaque.nim b/tests/modules/topaque.nim index 84e2388bc..94ff8ff25 100644 --- a/tests/modules/topaque.nim +++ b/tests/modules/topaque.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "undeclared field: \'buffer\'" file: "topaque.nim" line: 16 - errormsg: "undeclared field: \'buffer\'" """ # Test the new opaque types @@ -14,5 +14,3 @@ var L.filename = "ha" L.line = 34 L.buffer[0] = '\0' #ERROR_MSG undeclared field: 'buffer' - - diff --git a/tests/modules/torder_dep.nim b/tests/modules/torder_dep.nim new file mode 100644 index 000000000..85211228a --- /dev/null +++ b/tests/modules/torder_dep.nim @@ -0,0 +1,10 @@ +discard """ + output: '''[0, 0]''' +""" + +import morder_depb +import morder_depa + +# bug #11187 + +echo Foo(3) diff --git a/tests/modules/trecinca.nim b/tests/modules/trecinca.nim index 14a91ba5c..56798dedd 100644 --- a/tests/modules/trecinca.nim +++ b/tests/modules/trecinca.nim @@ -1,12 +1,10 @@ discard """ - file: "tests/reject/trecincb.nim" + errormsg: "recursive dependency: 'trecincb.nim'" + file: "trecincb.nim" line: 9 - errormsg: "recursive dependency: 'tests/modules/trecincb.nim'" """ # Test recursive includes include trecincb echo "trecina" - - diff --git a/tests/modules/trecincb.nim b/tests/modules/trecincb.nim index 299a242e1..30a5d7800 100644 --- a/tests/modules/trecincb.nim +++ b/tests/modules/trecincb.nim @@ -1,7 +1,7 @@ discard """ + errormsg: "recursive dependency: 'trecincb.nim'" file: "trecincb.nim" line: 9 - errormsg: "recursive dependency: 'tests/modules/trecincb.nim'" """ # Test recursive includes @@ -9,5 +9,3 @@ discard """ include trecincb echo "trecinb" - - diff --git a/tests/modules/trecmod.nim b/tests/modules/trecmod.nim index d567e293b..43e510e87 100644 --- a/tests/modules/trecmod.nim +++ b/tests/modules/trecmod.nim @@ -1,2 +1,8 @@ +discard """ + errormsg: "recursive module dependency detected" + file: "mrecmod.nim" + line: 1 + disabled: true +""" # recursive module import mrecmod diff --git a/tests/modules/trecmod2.nim b/tests/modules/trecmod2.nim index 85fe2215f..03c8cf70d 100644 --- a/tests/modules/trecmod2.nim +++ b/tests/modules/trecmod2.nim @@ -1,10 +1,13 @@ +discard """ + output: "4" +""" type T1* = int # Module A exports the type ``T1`` import mrecmod2 # the compiler starts parsing B - +# the manual says this should work proc main() = - var i = p(3) # works because B has been parsed completely here + echo p(3) # works because B has been parsed completely here main() diff --git a/tests/modules/treorder.nim b/tests/modules/treorder.nim new file mode 100644 index 000000000..ff0b2e071 --- /dev/null +++ b/tests/modules/treorder.nim @@ -0,0 +1,47 @@ +discard """ + matrix: "-d:testdef" + output: '''works 34 +34 +defined +3''' +""" + +{.experimental: "codeReordering".} + +{.push callconv: stdcall.} + +proc bar(x: T) + +proc foo() = + bar(34) + whendep() + +proc foo(dummy: int) = echo dummy + +proc bar(x: T) = + echo "works ", x + foo(x) + +when defined(testdef): + proc whendep() = echo "defined" +else: + proc whendep() = echo "undefined" + +foo() + +type + T = int + + +when not declared(goo): + proc goo(my, omy) = echo my + +when not declared(goo): + proc goo(my, omy) = echo omy + +using + my, omy: int + +goo(3, 4) + +{.pop.} diff --git a/tests/modules/tselfimport.nim b/tests/modules/tselfimport.nim index ddb3a5b09..ba5d9b4cf 100644 --- a/tests/modules/tselfimport.nim +++ b/tests/modules/tselfimport.nim @@ -1,9 +1,8 @@ discard """ + errormsg: "module 'tselfimport' cannot import itself" file: "tselfimport.nim" line: 7 - errormsg: "A module cannot import itself" """ import strutils as su # guard against regression import tselfimport #ERROR echo("Hello World") - diff --git a/tests/modules/tseq.nim b/tests/modules/tseq.nim new file mode 100644 index 000000000..22ee48f42 --- /dev/null +++ b/tests/modules/tseq.nim @@ -0,0 +1,8 @@ +discard """ + joinable: false + output: '''@[] +@[] +''' +""" + +import seq diff --git a/tests/modules/tstrutils_insert_sep.nim b/tests/modules/tstrutils_insert_sep.nim new file mode 100644 index 000000000..775fe7da1 --- /dev/null +++ b/tests/modules/tstrutils_insert_sep.nim @@ -0,0 +1,13 @@ +discard """ + output: ''' +-100 +-100,000 +100,000 +''' +""" +# test https://github.com/nim-lang/Nim/issues/11352 + +import strutils +echo insertSep($(-100), ',') +echo insertSep($(-100_000), ',') +echo insertSep($(100_000), ',') \ No newline at end of file diff --git a/tests/modules/tuppercased.nim b/tests/modules/tuppercased.nim new file mode 100644 index 000000000..65f41becd --- /dev/null +++ b/tests/modules/tuppercased.nim @@ -0,0 +1,8 @@ +discard """ + output: "hello" +""" + +import UpperCased + +# stress normalization rules: +echo Upper_Cased.str diff --git a/tests/modules/tutils_ab.nim b/tests/modules/tutils_ab.nim new file mode 100644 index 000000000..25bd08f3c --- /dev/null +++ b/tests/modules/tutils_ab.nim @@ -0,0 +1,5 @@ +import a/utils as autils, b/utils + +# bug #12420 + +burnMem(x) |