digitalmars.D - import statements inside unittests
- Victor Nakoryakov (8/8) Aug 17 2005 Hi all.
- Niko Korhonen (5/11) Aug 17 2005 I second this.
- Ben Hinkle (16/24) Aug 17 2005 I agree writing code that only compiles in unittest builds would be nice...
- Niko Korhonen (18/20) Aug 17 2005 A canonical example is printing some stuff in unit test in a module
- Victor Nakoryakov (7/46) Aug 17 2005 We already can define 'void func()' inside unittest, but 'import foo;' n...
- Ben Hinkle (7/52) Aug 17 2005 It would introduce a special case to parsing since import is not a
- Victor Nakoryakov (21/28) Aug 17 2005 Hmm, it is too bulky:
- Derek Parnell (6/11) Aug 17 2005 Yes, that would just wonderful.
- AJG (15/23) Aug 17 2005 Hi,
- Ben Hinkle (7/35) Aug 17 2005 Yeah - I'm worried about what it actually means, though. Should the impo...
- Ant (7/11) Aug 17 2005 Why do you say that?
- Ben Hinkle (20/32) Aug 17 2005 That sentance appears in the 'module' page. No mention of importing othe...
- Derek Parnell (10/14) Aug 17 2005 On Wed, 17 Aug 2005 16:47:54 -0400, Ben Hinkle wrote:
- Ben Hinkle (4/19) Aug 17 2005 ok - that's the point of this thread. Was there some confusion I missed?...
- AJG (46/56) Aug 17 2005 I'm not saying I know "the" answer to this one, nor is this a feature I'...
- Ben Hinkle (9/67) Aug 17 2005 This part so far is different than D today. mFooSymbol is available in t...
- Ben Hinkle (5/13) Aug 17 2005 Actually now that I think about it why is "private import" inadequate? A...
Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Aug 17 2005
Victor Nakoryakov wrote:Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds.I second this. -- Niko Korhonen SW Developer
Aug 17 2005
"Victor Nakoryakov" <nail-mail mail.ru> wrote in message news:ddv03k$2aug$1 digitaldaemon.com...Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, RussiaI agree writing code that only compiles in unittest builds would be nice. I think the compiler should define a version Unittest (or something like that) when unittests are enabled. That way you can have version(Unittest) { import foo; void func() { ... some helper function... } unittest { the tests... } } and even add unittest-only code to classes being tested to get data or dump contents that wouldn't be built into release versions.
Aug 17 2005
Ben Hinkle wrote:and even add unittest-only code to classes being tested to get data or dump contents that wouldn't be built into release versions.A canonical example is printing some stuff in unit test in a module where cstream would not otherwise be needed: <code> import std.cstream; // only for unit test unittest { int x, y, z; // .. dout.writefln("Debug dump of some vars: ", x, y, z); } </code> I could use printf in unit tests without importing std.cstream, but then I can't specify whether to write to dout or derr and I just like writefln too much :) -- Niko Korhonen SW Developer
Aug 17 2005
Ben Hinkle wrote:"Victor Nakoryakov" <nail-mail mail.ru> wrote in message news:ddv03k$2aug$1 digitaldaemon.com...Maybe version(Unittest) is even superfluous if you would able to write:Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, RussiaI agree writing code that only compiles in unittest builds would be nice. I think the compiler should define a version Unittest (or something like that) when unittests are enabled. That way you can have version(Unittest) { import foo; void func() { ... some helper function... } unittest { the tests... } } and even add unittest-only code to classes being tested to get data or dump contents that wouldn't be built into release versions.unittest { import foo; void func() { ... some helper function... } the tests... }We already can define 'void func()' inside unittest, but 'import foo;' not. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Aug 17 2005
"Victor Nakoryakov" <nail-mail mail.ru> wrote in message news:ddvhve$2tc2$1 digitaldaemon.com...Ben Hinkle wrote:It would introduce a special case to parsing since import is not a statement. I'd rather not add a special case for parsing and instead add the more general Unittest version identifier and leverage the existing conditional compilation mechanisms. Importing a module only in certain builds is just what conditional compilation is good at doing."Victor Nakoryakov" <nail-mail mail.ru> wrote in message news:ddv03k$2aug$1 digitaldaemon.com...Maybe version(Unittest) is even superfluous if you would able to write:Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, RussiaI agree writing code that only compiles in unittest builds would be nice. I think the compiler should define a version Unittest (or something like that) when unittests are enabled. That way you can have version(Unittest) { import foo; void func() { ... some helper function... } unittest { the tests... } } and even add unittest-only code to classes being tested to get data or dump contents that wouldn't be built into release versions.unittest { import foo; void func() { ... some helper function... } the tests... }We already can define 'void func()' inside unittest, but 'import foo;' not. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Aug 17 2005
It would introduce a special case to parsing since import is not a statement. I'd rather not add a special case for parsing and instead add the more general Unittest version identifier and leverage the existing conditional compilation mechanisms. Importing a module only in certain builds is just what conditional compilation is good at doing.Hmm, it is too bulky: version (Unittests) { import std.string; unittest { ... } } instead of: unittest { import std.string; ... } I didn't search place in source where dmd parses unittests yet, but I don't think that adding this feature need much work. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Aug 17 2005
On Wed, 17 Aug 2005 13:29:14 +0400, Victor Nakoryakov wrote:Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds.Yes, that would just wonderful. -- Derek Parnell Melbourne, Australia 17/08/2005 11:02:19 PM
Aug 17 2005
Hi, What about arbitrarily nested import statements? ~Foo.d: Seems more useful than a special case for unittest. --AJG. In article <ddv03k$2aug$1 digitaldaemon.com>, Victor Nakoryakov says...Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Aug 17 2005
"AJG" <AJG_member pathlink.com> wrote in message news:ddvsig$4so$1 digitaldaemon.com...Hi, What about arbitrarily nested import statements? ~Foo.d: Seems more useful than a special case for unittest. --AJG.Yeah - I'm worried about what it actually means, though. Should the imported symbols only be visible after the executed statement or throughout the scope body? . Also given that imports inside classes and structs are discouraged (and undocumented I believe) by Walter I'd imagine that putting them inside functions will be even more hairy.In article <ddv03k$2aug$1 digitaldaemon.com>, Victor Nakoryakov says...Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, Russia
Aug 17 2005
In article <de04ab$b14$1 digitaldaemon.com>, Ben Hinkle says...Should the imported symbols only be visible after the executed statement or throughout the scope body? . Also given that imports inside classes and structs are discouraged (and undocumented I believe) by WalterWhy do you say that? "The top level scope in the module is merged with the current scope." from http://www.digitalmars.com//d/index.html I see no limitation on "current scope", but I remember a compiler message about the scope of the import declaration. Ant
Aug 17 2005
"Ant" <Ant_member pathlink.com> wrote in message news:de050d$blb$1 digitaldaemon.com...In article <de04ab$b14$1 digitaldaemon.com>, Ben Hinkle says...That sentance appears in the 'module' page. No mention of importing other than at the top level of a module is made in the D docs (from what I could tell). The production DeclDefs in module.html is the only place I could find imports explicitly listed in the "grammar" such as it is. For example the next section "Scope and Modules" only talks about importing a module into another module. The classes.html doc doesn't talk about importing or what it means (in general the classes.html never seems to actually say what's allowed inside a class body). If one interprets "current scope" as really meaning any scope then it would also include function scopes - which currently doesn't work. So I think attaching too much meaning to the words "current scope" is dangerous - the web pages are .. umm... informal. I also briefly tried searching for a post I recall where he suggested people avoid importing inside class bodies even though it technically works (depending on bugs, I think). None of the threads with the obvious subject names had anything useful and it's impossible to search those long meandering threads with generic subjects. I know several people argued strongly that they try to import inside classes as much as possible so it's a touchy subject.Should the imported symbols only be visible after the executed statement or throughout the scope body? . Also given that imports inside classes and structs are discouraged (and undocumented I believe) by WalterWhy do you say that? "The top level scope in the module is merged with the current scope." from http://www.digitalmars.com//d/index.html I see no limitation on "current scope", but I remember a compiler message about the scope of the import declaration. Ant
Aug 17 2005
On Wed, 17 Aug 2005 16:47:54 -0400, Ben Hinkle wrote: [snip]No mention of importing other than at the top level of a module is made in the D docs (from what I could tell). The production DeclDefs in module.html is the only place I could find imports explicitly listed in the "grammar" such as it is ...Backing up a little ... it would be useful if Walter could provide an easy-to-use mechanism so that specific imports only occurred during unit testing. -- Derek Parnell Melbourne, Australia 18/08/2005 6:56:15 AM
Aug 17 2005
"Derek Parnell" <derek psych.ward> wrote in message news:1jg0ds14poumr.gmvd6saz5sez$.dlg 40tude.net...On Wed, 17 Aug 2005 16:47:54 -0400, Ben Hinkle wrote: [snip]ok - that's the point of this thread. Was there some confusion I missed? AJG was generalizing the original proposal.No mention of importing other than at the top level of a module is made in the D docs (from what I could tell). The production DeclDefs in module.html is the only place I could find imports explicitly listed in the "grammar" such as it is ...Backing up a little ... it would be useful if Walter could provide an easy-to-use mechanism so that specific imports only occurred during unit testing. -- Derek Parnell Melbourne, Australia 18/08/2005 6:56:15 AM
Aug 17 2005
Hi,I'm not saying I know "the" answer to this one, nor is this a feature I'm desperate about, but to me it would mean something like the following: ~Foo.d: Don't know if I missed any cases in there.Hi, What about arbitrarily nested import statements? Seems more useful than a special case for unittest. --AJG.Yeah - I'm worried about what it actually means, though. Should the imported symbols only be visible after the executed statement or throughout the scope body? .Also given that imports inside classes and structs are discouraged (and undocumented I believe) by Walter I'd imagine that putting them inside functions will be even more hairy.Do you mean semantically or in terms of the compiler's own implementation? Cheers, --AJG.
Aug 17 2005
"AJG" <AJG_member pathlink.com> wrote in message news:de069s$cpb$1 digitaldaemon.com...Hi,This part so far is different than D today. mFooSymbol is available in the first line.I'm not saying I know "the" answer to this one, nor is this a feature I'm desperate about, but to me it would mean something like the following: ~Foo.d:Hi, What about arbitrarily nested import statements? Seems more useful than a special case for unittest. --AJG.Yeah - I'm worried about what it actually means, though. Should the imported symbols only be visible after the executed statement or throughout the scope body? .This is different, too.Don't know if I missed any cases in there.Personally if putting restrictions on the places where imports are allowed helps make compilers simpler and less buggy (eg Java forces all imports at the top) then I'm all for it. The current documentation on imports is very vague.Also given that imports inside classes and structs are discouraged (and undocumented I believe) by Walter I'd imagine that putting them inside functions will be even more hairy.Do you mean semantically or in terms of the compiler's own implementation? Cheers, --AJG.
Aug 17 2005
"Victor Nakoryakov" <nail-mail mail.ru> wrote in message news:ddv03k$2aug$1 digitaldaemon.com...Hi all. Is there any reason for forbiding import statements inside unittests? I often want import some module just for testing purposes only and do not want keep this dependency in release builds. -- Victor (aka nail) Nakoryakov nail-mail<at>mail<dot>ru Krasnoznamensk, Moscow, RussiaActually now that I think about it why is "private import" inadequate? A private import should have no effect on modules that import the original module.
Aug 17 2005