digitalmars.D - Should unittests run as logical part of compilation?
- Andrei Alexandrescu (25/25) Jan 25 2014 There's this simple realization that unittests could (should?) be
- deadalnix (4/30) Jan 25 2014 +1, unittest passed as command line argument to dmd should run
- Jakob Ovrum (8/20) Jan 25 2014 This idiom is probably mostly obsolete now that we have the -main
- =?UTF-8?B?U2ltZW4gS2rDpnLDpXM=?= (10/25) Jan 26 2014 Except that would exclude any unit tests in the module that defines main...
- Johannes Pfau (5/14) Jan 25 2014 But please keep some way to manually run unittests - otherwise cross
- bearophile (8/13) Jan 25 2014 This is an example of bit a more general need: in D I'd like to
- Mike (20/29) Jan 25 2014 How does this work for those who build on one machine and test on
- Andrei Alexandrescu (5/21) Jan 26 2014 Yah, thanks (and Johannes too) for making this point. That means we
- Jesse Phillips (12/21) Jan 25 2014 I already attempt to get unittests to fail at compile time by
- Jacob Carlborg (5/8) Jan 26 2014 It's already possible to do CTFE unit tests:
- Andrei Alexandrescu (4/18) Jan 26 2014 That's great but I wasn't thinking of CTFEing unittests as much as just
- Jesse Phillips (4/13) Jan 26 2014 I'm aware of that, my point being that I'm already trying to get
- Rikki Cattermole (11/17) Jan 25 2014 My idea for pragma(error,) and pragma(warning,) would definately
- H. S. Teoh (8/22) Jan 25 2014 +1. Some of my unittests can only be run at runtime: like testing file
- anonymous (3/21) Jan 26 2014 I don't think the tests are supposed to be CTFE'd. They'd be
- Andrei Alexandrescu (3/18) Jan 26 2014 Yah, that was my idea.
- Atila Neves (3/8) Jan 27 2014 Tests that do I/O aren't unit tests. They're more likely
- Jacob Carlborg (5/7) Jan 26 2014 That's already possible:
- Andrei Alexandrescu (3/8) Jan 26 2014 What about static assert(false, "message")?
- simendsjo (12/17) Jan 26 2014 (...)
- Dicebot (9/27) Jan 26 2014 I simply think that "-unittest" should not emit any existing
- Andrei Alexandrescu (4/18) Jan 26 2014 Does it help that the client runs them every time? I.e. does the n+1th
- H. S. Teoh (11/32) Jan 26 2014 [...]
- Idan Arye (23/49) Jan 26 2014 I don't think unit tests should be run on *each* build - if I'm
- Andrei Alexandrescu (8/26) Jan 26 2014 Hah, interesting. So unittests of one module should run again iff there
- Jesse Phillips (5/8) Jan 26 2014 I really think it would be better to use
- Andrei Alexandrescu (3/9) Jan 26 2014 I'm just saying it should not clash with any application argument.
- H. S. Teoh (9/19) Jan 26 2014 [...]
- Andrei Alexandrescu (6/22) Jan 27 2014 I don't see that a special case. The only idea here is to produce one
- Alix Pexton (7/17) Jan 27 2014 Hows about making it so that unittests are only run if the executable
- Idan Arye (4/26) Jan 27 2014 How about exposing the sybmol of the function that runs the
- Dicebot (2/5) Jan 27 2014 It is already possible via library solution.
- Andrei Alexandrescu (5/21) Jan 27 2014 Something like that would work nicely with a build system - the
- Steven Schveighoffer (16/18) Jan 26 2014 After reading other opinions, this is what I think:
- Andrei Alexandrescu (6/23) Jan 26 2014 Guess we'd need to keep things running as they do for backwards
- Gary Willoughby (10/36) Jan 26 2014 I don't fully understand this. Are you proposing to disconnect
- Andrei Alexandrescu (4/12) Jan 26 2014 We'd need to preserve backward compatibility.
- Ary Borenszweig (5/10) Jan 26 2014 I can imagine someone who discovered a bug late at night, has a fix and
- Andrei Alexandrescu (3/13) Jan 26 2014 The point being?
- Ary Borenszweig (4/18) Jan 27 2014 That it's annoying if you can't build an executable because some tests
- Andrei Alexandrescu (3/24) Jan 27 2014 Got it, thanks.
- Knud Soerensen (22/55) Jan 26 2014 I am already doing something very similar.
- Atila Neves (5/31) Jan 27 2014 I share the opinion others have expressed here that running unit
- =?windows-1252?Q?Simen_Kj=E6r=E5s?= (10/12) Jan 27 2014 As evinced by Bugzilla 5091[0], I always run unit tests separately from
There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined message Stack traces and other artifacts printed by failing asserts should come after, indented. An IDE user should run unittest with the usual "build" command and be able to click on the unittest failures just the same as build errors. In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... } What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach. Andrei
Jan 25 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined message Stack traces and other artifacts printed by failing asserts should come after, indented. An IDE user should run unittest with the usual "build" command and be able to click on the unittest failures just the same as build errors. In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... } What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach. Andrei+1, unittest passed as command line argument to dmd should run unittests as compilation step and main should remain untouched.
Jan 25 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... }This idiom is probably mostly obsolete now that we have the -main flag. An IDE can build with -unittest -main -run and exclude the source file that normally defines `main`.What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach.I like it, as long as it doesn't mean unit tests are enabled by default, as that would probably be very surprising both for building release binaries and from a security perspective.
Jan 25 2014
On 2014-01-25 23:06, Jakob Ovrum wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:Except that would exclude any unit tests in the module that defines main. Of course, if you want to be evil, you could even write unit tests for main: int main() { return 3; } unittest { assert(main() == 3); } -- SimenIn particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... }This idiom is probably mostly obsolete now that we have the -main flag. An IDE can build with -unittest -main -run and exclude the source file that normally defines `main`.
Jan 26 2014
Am Sat, 25 Jan 2014 14:55:30 -0800 schrieb Andrei Alexandrescu <SeeWebsiteForEmail erdani.org>:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. [....] AndreiBut please keep some way to manually run unittests - otherwise cross compilers will have lots of fun running unittests ;-) (IMHO this is the responsibility of a build tool, not of the compiler)
Jan 25 2014
Andrei Alexandrescu:version(unittest) void main() {} else void main() { ... }This is an example of bit a more general need: in D I'd like to create modules that can be imported from other modules to use their functionality; and to run their own main() when they are not imported from other modules. It's a simple feature that is still missing in D. Bye, bearophile
Jan 25 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. [...] What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach.How does this work for those who build on one machine and test on another? I'm currently building on a Linux host, and deploying to a bare-metal ARM Cortex-M processor. Also, with limited amounts of flash, I may only have enough room for unit tests or my program, but not both. (Just so you know, I don't actually use the unit test feature yet, but I intend to) This seems more like a workflow feature rather than a build feature. But integration into the toolchain could be pretty cool (like you said, clicking on a messages in the output window, and zooming right to the point of failure). It seems to me that having an additional tool in the tool chain (the unit tester) along with the compiler, linker, debugger, etc.. that could be initiated by the build process, is the way to go. If compiling unit tests, the build process could generate a unit test executable, run the unit test executable, and, assuming all tests pass, then generate the production executable. I think such a tool could scale to my platform, somehow, I suppose. Mike
Jan 25 2014
On 1/25/14 4:26 PM, Mike wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:Yah, thanks (and Johannes too) for making this point. That means we should not prevent the option of running them separately.There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. [...] What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach.How does this work for those who build on one machine and test on another?This seems more like a workflow feature rather than a build feature. But integration into the toolchain could be pretty cool (like you said, clicking on a messages in the output window, and zooming right to the point of failure).That is correct - an build environment thing. Andrei
Jan 26 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined messageI already attempt to get unittests to fail at compile time by using static assert. I think running it during compilation would be a great change. Though cross compiling is a valid concern and should be addressed. Many are use to the notion that unittest are separate from compilation, I think this is only due to familiarity. Other than the cross-compile issue, I believe moving it closer to the time of compilation is the correct direction, but it will get distaste from those familiar with JUnit/NUnit and other unittesting frameworks just as it currently does.
Jan 25 2014
On 2014-01-26 04:52, Jesse Phillips wrote:I already attempt to get unittests to fail at compile time by using static assert. I think running it during compilation would be a great change. Though cross compiling is a valid concern and should be addressed.It's already possible to do CTFE unit tests: http://forum.dlang.org/thread/ks1brj$1l6c$1 digitalmars.com -- /Jacob Carlborg
Jan 26 2014
On 1/25/14 7:52 PM, Jesse Phillips wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:That's great but I wasn't thinking of CTFEing unittests as much as just running them right after building. AndreiThere's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined messageI already attempt to get unittests to fail at compile time by using static assert. I think running it during compilation would be a great change.
Jan 26 2014
On Monday, 27 January 2014 at 03:45:00 UTC, Andrei Alexandrescu wrote:On 1/25/14 7:52 PM, Jesse Phillips wrote:I'm aware of that, my point being that I'm already trying to get them to run as frequently as possible.I already attempt to get unittests to fail at compile time by using static assert. I think running it during compilation would be a great change.That's great but I wasn't thinking of CTFEing unittests as much as just running them right after building. Andrei
Jan 26 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:./modulename.d(103): Unittest failed: user-defined messageMy idea for pragma(error,) and pragma(warning,) would definately be invaluable to doing this without adding this specific behaviour. (Really should deal with that.)In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs:Having the ability to run unittests at both compile time and runtime would be useful. Because what happens when you need to test e.g. an OS feature with it? Or have a dependency that simply cannot run at compile time? I'm all for being able to selectively run unittests and having the ability to have some run at compile time.
Jan 25 2014
On Sun, Jan 26, 2014 at 04:29:10AM +0000, Rikki Cattermole wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:[...]+1. Some of my unittests can only be run at runtime: like testing file I/O. Obviously, other unittests can also be run at compile-time, so it's useful to have both. T -- Кто везде - тот нигде.In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs:Having the ability to run unittests at both compile time and runtime would be useful. Because what happens when you need to test e.g. an OS feature with it? Or have a dependency that simply cannot run at compile time? I'm all for being able to selectively run unittests and having the ability to have some run at compile time.
Jan 25 2014
On Sunday, 26 January 2014 at 05:17:15 UTC, H. S. Teoh wrote:On Sun, Jan 26, 2014 at 04:29:10AM +0000, Rikki Cattermole wrote:I don't think the tests are supposed to be CTFE'd. They'd be compiled (to a temporary executable?) and then run normally.Having the ability to run unittests at both compile time and runtime would be useful. Because what happens when you need to test e.g. an OS feature with it? Or have a dependency that simply cannot run at compile time? I'm all for being able to selectively run unittests and having the ability to have some run at compile time.+1. Some of my unittests can only be run at runtime: like testing file I/O. Obviously, other unittests can also be run at compile-time, so it's useful to have both.
Jan 26 2014
On 1/26/14 3:20 AM, anonymous wrote:On Sunday, 26 January 2014 at 05:17:15 UTC, H. S. Teoh wrote:Yah, that was my idea. AndreiOn Sun, Jan 26, 2014 at 04:29:10AM +0000, Rikki Cattermole wrote:I don't think the tests are supposed to be CTFE'd. They'd be compiled (to a temporary executable?) and then run normally.Having the ability to run unittests at both compile time and runtime would be useful. Because what happens when you need to test e.g. an OS feature with it? Or have a dependency that simply cannot run at compile time? I'm all for being able to selectively run unittests and having the ability to have some run at compile time.+1. Some of my unittests can only be run at runtime: like testing file I/O. Obviously, other unittests can also be run at compile-time, so it's useful to have both.
Jan 26 2014
+1. Some of my unittests can only be run at runtime: like testing file I/O. Obviously, other unittests can also be run at compile-time, so it's useful to have both.Tests that do I/O aren't unit tests. They're more likely integration tests. Atila
Jan 27 2014
On 2014-01-26 05:29, Rikki Cattermole wrote:I'm all for being able to selectively run unittests and having the ability to have some run at compile time.That's already possible: http://forum.dlang.org/thread/ks1brj$1l6c$1 digitalmars.com -- /Jacob Carlborg
Jan 26 2014
On 1/25/14 8:29 PM, Rikki Cattermole wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:What about static assert(false, "message")? Andrei./modulename.d(103): Unittest failed: user-defined messageMy idea for pragma(error,) and pragma(warning,) would definately be invaluable to doing this without adding this specific behaviour. (Really should deal with that.)
Jan 26 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process.(...)In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless.(...) I wouldn't mind having unittests be a part of the compilation process, but I really don't think "running before main" is useless. This lets me compile a version on my desktop and push the binary to a small VPS staging for running runtime tests. Compiling any non-trivial code on 512MB with the DMD frontend is impossible. I can also send a fully working application with unittests to a client as a beta before giving a production version.
Jan 26 2014
On Sunday, 26 January 2014 at 11:25:25 UTC, simendsjo wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:I simply think that "-unittest" should not emit any existing "main" function by default (only stub one if --main is set) and other than that we are pretty good at current stage. Running tests is necessary part of build system indeed but dmd is not a build system and should not force any assumptions about it. Initial idea to make tests always run before the program starts does not work though, that is true. But currently we have enough tools to do it in any way specific project needs.There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process.(...)In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless.(...) I wouldn't mind having unittests be a part of the compilation process, but I really don't think "running before main" is useless. This lets me compile a version on my desktop and push the binary to a small VPS staging for running runtime tests. Compiling any non-trivial code on 512MB with the DMD frontend is impossible. I can also send a fully working application with unittests to a client as a beta before giving a production version.
Jan 26 2014
On 1/26/14 3:25 AM, simendsjo wrote:On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:Does it help that the client runs them every time? I.e. does the n+1th run of the unittests bring more information than the first? AndreiThere's this simple realization that unittests could (should?) be considered an intrinsic part of the build process.(...)In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless.(...) I wouldn't mind having unittests be a part of the compilation process, but I really don't think "running before main" is useless. This lets me compile a version on my desktop and push the binary to a small VPS staging for running runtime tests. Compiling any non-trivial code on 512MB with the DMD frontend is impossible. I can also send a fully working application with unittests to a client as a beta before giving a production version.
Jan 26 2014
On Sun, Jan 26, 2014 at 07:53:30PM -0800, Andrei Alexandrescu wrote:On 1/26/14 3:25 AM, simendsjo wrote:[...] It's very useful when you're in a code-compile-run development cycle, when you're likely to be making some further changes after every execution. Any regressions are quickly caught by unittests. Obviously, it's useless to run the same unittests twice when nothing has changed, but then, I thought the idea was that you *don't* compile with -unittest when shipping the executable. T -- Once the bikeshed is up for painting, the rainbow won't suffice. -- Andrei AlexandrescuOn Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:Does it help that the client runs them every time? I.e. does the n+1th run of the unittests bring more information than the first?There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process.(...)In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless.(...) I wouldn't mind having unittests be a part of the compilation process, but I really don't think "running before main" is useless. This lets me compile a version on my desktop and push the binary to a small VPS staging for running runtime tests. Compiling any non-trivial code on 512MB with the DMD frontend is impossible. I can also send a fully working application with unittests to a client as a beta before giving a production version.
Jan 26 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined message Stack traces and other artifacts printed by failing asserts should come after, indented. An IDE user should run unittest with the usual "build" command and be able to click on the unittest failures just the same as build errors. In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... } What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach. AndreiI don't think unit tests should be run on *each* build - if I'm fidgeting with a specific piece of my code, and building&running it after each change, I don't want to waste time running the unittests of the entire project. I do agree that unittests shouldn't be part of each run though. I think the `-unittest` flag should ignore the `main` function altogether, creating a unittests only executable, and the build system will be responsible for running it. How about keeping the old behavior of `-unittest` for backward compatibility, and having a new syntax - `-unittest=filename`, where "filename" is the name of the unittests executable. That way both the unittest and the regular executables will be created at the same time - which will speed things up, as most of the compilation work can be shared between those two builds - and have different file names, so the build system - which will make configuring the build system more straightforward. If we make the unittest a separate executable, there won't be a `main` function waiting for command line arguments, so we can use the command line arguments for the unittests. We can have flags for only running tests of specific packages, or for running the tests under certain restrictions etc.
Jan 26 2014
On 1/26/14 4:58 AM, Idan Arye wrote:I don't think unit tests should be run on *each* build - if I'm fidgeting with a specific piece of my code, and building&running it after each change, I don't want to waste time running the unittests of the entire project.Hah, interesting. So unittests of one module should run again iff there were changes in that module or other modules that that depends on.How about keeping the old behavior of `-unittest` for backward compatibility, and having a new syntax - `-unittest=filename`, where "filename" is the name of the unittests executable.Sounds interesting.That way both the unittest and the regular executables will be created at the same time - which will speed things up, as most of the compilation work can be shared between those two builds - and have different file names, so the build system - which will make configuring the build system more straightforward.Yeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".If we make the unittest a separate executable, there won't be a `main` function waiting for command line arguments, so we can use the command line arguments for the unittests. We can have flags for only running tests of specific packages, or for running the tests under certain restrictions etc.There we go :o). Andrei
Jan 26 2014
On Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:Yeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.
Jan 26 2014
On 1/26/14 8:08 PM, Jesse Phillips wrote:On Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:I'm just saying it should not clash with any application argument. AndreiYeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.
Jan 26 2014
On Sun, Jan 26, 2014 at 08:15:23PM -0800, Andrei Alexandrescu wrote:On 1/26/14 8:08 PM, Jesse Phillips wrote:[...] That won't work if the application is a git client looking for an SHA hash argument... Let's not add arbitrary things like this to D programs, it doesn't address the issue and only introduces needless special cases. T -- "Hi." "'Lo."On Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:I'm just saying it should not clash with any application argument.Yeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.
Jan 26 2014
On 1/26/14 10:08 PM, H. S. Teoh wrote:On Sun, Jan 26, 2014 at 08:15:23PM -0800, Andrei Alexandrescu wrote:Of course it works unless there's a clash with this particular SHA.On 1/26/14 8:08 PM, Jesse Phillips wrote:[...] That won't work if the application is a git client looking for an SHA hash argument...On Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:I'm just saying it should not clash with any application argument.Yeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.Let's not add arbitrary things like this to D programs, it doesn't address the issue and only introduces needless special cases.I don't see that a special case. The only idea here is to produce one single debug executable containing unittests and running them on demand (e.g. by the build system). Andrei
Jan 27 2014
On 27/01/2014 4:15 AM, Andrei Alexandrescu wrote:On 1/26/14 8:08 PM, Jesse Phillips wrote:Hows about making it so that unittests are only run if the executable name has a "_ut" suffix, or some other special name/convention? A... --- This email is free from viruses and malware because avast! Antivirus protection is active. http://www.avast.comOn Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:I'm just saying it should not clash with any application argument. AndreiYeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.
Jan 27 2014
On Monday, 27 January 2014 at 11:10:04 UTC, Alix Pexton wrote:On 27/01/2014 4:15 AM, Andrei Alexandrescu wrote:How about exposing the sybmol of the function that runs the unittest, and having a "dunittest" tool for running the tests stored inside a regular executable? (I think it's possible?)On 1/26/14 8:08 PM, Jesse Phillips wrote:Hows about making it so that unittests are only run if the executable name has a "_ut" suffix, or some other special name/convention? A...On Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:I'm just saying it should not clash with any application argument. AndreiYeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.
Jan 27 2014
On Monday, 27 January 2014 at 12:18:55 UTC, Idan Arye wrote:How about exposing the sybmol of the function that runs the unittest, and having a "dunittest" tool for running the tests stored inside a regular executable? (I think it's possible?)It is already possible via library solution.
Jan 27 2014
On 1/27/14 3:10 AM, Alix Pexton wrote:On 27/01/2014 4:15 AM, Andrei Alexandrescu wrote:Something like that would work nicely with a build system - the executable name has a specific suffix and is promoted to the non-unittest suffix once it has passed unittests. AndreiOn 1/26/14 8:08 PM, Jesse Phillips wrote:Hows about making it so that unittests are only run if the executable name has a "_ut" suffix, or some other special name/convention? A...On Monday, 27 January 2014 at 03:58:54 UTC, Andrei Alexandrescu wrote:I'm just saying it should not clash with any application argument. AndreiYeppers. One other thought I had was to define a special flag e.g. --4c5ad7908c2aa1b3de32ea25968cdf49 that says "just run unittests".I really think it would be better to use --4c5ad7908c2aa1b3de42ea25968cdf49 instead, it just makes the intent clearer.
Jan 27 2014
On Sat, 25 Jan 2014 17:55:30 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach.After reading other opinions, this is what I think: 1. unit tests should be built as a separate binary. So when you build foo with -unittest, you get foo_unittest in addition to foo. 2. If you want to run unit tests, run foo_unittest. If you want simply the program, run foo. I don't see a huge need for having unit tests run before the normal program. But maybe we should add a switch to make that work. Building and running it as part of compilation seems like an incorrect function of the compiler. This is best left to an IDE/build script. Also, building unit tests still needs to be opt-in. Some projects can take a long time to build unit tests (dcollections takes about 20x longer to compile unit tests, last time I checked), and a quick compile-test-debug cycle is a key feature of D. -Steve
Jan 26 2014
On 1/26/14 12:43 PM, Steven Schveighoffer wrote:On Sat, 25 Jan 2014 17:55:30 -0500, Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> wrote:Makes sense, though we could massage the unittests into the executable.What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach.After reading other opinions, this is what I think: 1. unit tests should be built as a separate binary. So when you build foo with -unittest, you get foo_unittest in addition to foo. 2. If you want to run unit tests, run foo_unittest. If you want simply the program, run foo.I don't see a huge need for having unit tests run before the normal program. But maybe we should add a switch to make that work.Guess we'd need to keep things running as they do for backwards compatibility.Building and running it as part of compilation seems like an incorrect function of the compiler. This is best left to an IDE/build script. Also, building unit tests still needs to be opt-in. Some projects can take a long time to build unit tests (dcollections takes about 20x longer to compile unit tests, last time I checked), and a quick compile-test-debug cycle is a key feature of D.Yah it should be all nicely controllable by the build system. Andrei
Jan 26 2014
On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined message Stack traces and other artifacts printed by failing asserts should come after, indented. An IDE user should run unittest with the usual "build" command and be able to click on the unittest failures just the same as build errors. In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... } What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach. AndreiI don't fully understand this. Are you proposing to disconnect running unittest and evoking main? So unittests can be compiled and run without actually running the program? If this is the case then yes it would be nice to be able to do this but i would also recommend keeping the current behaviour of invoking main after the unittests have run, purely because developers (myself included) like to run the application often in debug/unittest mode during development.
Jan 26 2014
On 1/26/14 1:04 PM, Gary Willoughby wrote:I don't fully understand this. Are you proposing to disconnect running unittest and evoking main? So unittests can be compiled and run without actually running the program?Right.If this is the case then yes it would be nice to be able to do this but i would also recommend keeping the current behaviour of invoking main after the unittests have run, purely because developers (myself included) like to run the application often in debug/unittest mode during development.We'd need to preserve backward compatibility. Andrei
Jan 26 2014
On 1/25/14, 7:55 PM, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler.I can imagine someone who discovered a bug late at night, has a fix and needs to upload the new executable as soon as possible: he quickly comments all failing unit tests to make them pass. The next morning he uncomments them and fixes them with tranquility.
Jan 26 2014
On 1/26/14 5:36 PM, Ary Borenszweig wrote:On 1/25/14, 7:55 PM, Andrei Alexandrescu wrote:The point being? AndreiThere's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler.I can imagine someone who discovered a bug late at night, has a fix and needs to upload the new executable as soon as possible: he quickly comments all failing unit tests to make them pass. The next morning he uncomments them and fixes them with tranquility.
Jan 26 2014
On 1/27/14, 1:04 AM, Andrei Alexandrescu wrote:On 1/26/14 5:36 PM, Ary Borenszweig wrote:That it's annoying if you can't build an executable because some tests fail. Sometimes you know tests fail but you didn't have time to fix them (but you did fix the code).On 1/25/14, 7:55 PM, Andrei Alexandrescu wrote:The point being? AndreiThere's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler.I can imagine someone who discovered a bug late at night, has a fix and needs to upload the new executable as soon as possible: he quickly comments all failing unit tests to make them pass. The next morning he uncomments them and fixes them with tranquility.
Jan 27 2014
On 1/27/14 3:39 AM, Ary Borenszweig wrote:On 1/27/14, 1:04 AM, Andrei Alexandrescu wrote:Got it, thanks. AndreiOn 1/26/14 5:36 PM, Ary Borenszweig wrote:That it's annoying if you can't build an executable because some tests fail. Sometimes you know tests fail but you didn't have time to fix them (but you did fix the code).On 1/25/14, 7:55 PM, Andrei Alexandrescu wrote:The point being? AndreiThere's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler.I can imagine someone who discovered a bug late at night, has a fix and needs to upload the new executable as soon as possible: he quickly comments all failing unit tests to make them pass. The next morning he uncomments them and fixes them with tranquility.
Jan 27 2014
I am already doing something very similar. When I make a module I add this to the top. (I would like to add -cov=100 but I can't get it to work) Then I just run the module to compile and run unit tests. My programs with main is always very small, typical calling a module function with the arguments. Doing the unit testing in the end of the compile would mean that we could ensure that dependencies was unit testing before use. That would be nice. Another thing I find really tedious about D unit testing can you read about here. http://forum.dlang.org/post/lc514a$sd7$1 digitalmars.com Knud On 2014-01-25 23:55, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined message Stack traces and other artifacts printed by failing asserts should come after, indented. An IDE user should run unittest with the usual "build" command and be able to click on the unittest failures just the same as build errors. In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... } What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach. Andrei-- Join me on Skype knudhs Facebook http://www.facebook.com/profile.php?id=1198821880 Linkedin http://www.linkedin.com/pub/0/117/a54 Twitter http://twitter.com/knudsoerensen bitcoin donations: 13ofyUKqFL43uRJHZtNozyMVP4qxKPsAR2
Jan 26 2014
I share the opinion others have expressed here that running unit tests should be the responsability of the build system. Atila On Saturday, 25 January 2014 at 22:55:33 UTC, Andrei Alexandrescu wrote:There's this simple realization that unittests could (should?) be considered an intrinsic part of the build process. In order for an executable to be worth running, it should pass the regular semantic checks and also the unittests, which in a sense are extended semantic checks that fall outside the traditional charter of the compiler. In that view, asserts inside unittests should fail with the same message format as regular compilation errors, i.e. ./modulename.d(103): Unittest failed: user-defined message Stack traces and other artifacts printed by failing asserts should come after, indented. An IDE user should run unittest with the usual "build" command and be able to click on the unittest failures just the same as build errors. In particular, this view of unittests declares our current stance on running unittests ("run unittests just before main()") as meaningless. Indeed that has bothered me for quite a while - unittests are part of the build/acceptance, not part of every run. To wit, this is a growing idiom in D programs: version(unittest) void main() {} else void main() { ... } What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach. Andrei
Jan 27 2014
On 2014-01-25 22:55, Andrei Alexandrescu wrote: [Good stuff]What do you think? Logistically it shouldn't be too hard to arrange things to cater to this approach.As evinced by Bugzilla 5091[0], I always run unit tests separately from the rest of the program, and so fully support this motion. As others have pointed out, there are possible problems with cross-compilation, but all in all, I think treating unit tests as a build step rather than something to do with execution is a Good Thing™. [0]: https://d.puremagic.com/issues/show_bug.cgi?id=5091 -- Simen
Jan 27 2014