News for hackers. Stuff that matters.

Ask HN: Is there a programming language with embedded testing support?

There are many dimensions to programming languages that range from systems to scripting, weakly typed to strongly typed, dynamic to static typed, purely functional to statefull, imperative to declarative, etc...

There are also very few languages that focus on correctness and contracts to help create programs that have fewer bugs. Yet The mayority of languages simply focus on "getting things done", so to speak, and leave testing and correctness out of the picture or add them later on.

Granted, testing support can be added later via libraries and frameworks, but I wonder: in the continuum of program correctness, is there a language that perhaps does not provide full proof/correctness/contract support but does come with testing right out of the box, either in its implementation or philosophy?

Also related question: do you know of any language that was specifically designed to encourage and/or make testing easier for its programs?

Even though I didn't get the "joke" for a recent post about Go[0], I still think it's interesting to ask.

[0] https://news.ycombinator.com/item?id=12371029

( 11 comments | 15 points | on HN )
Re:Ask HN: Is there a programming language with embedded tes... by tomjen3 on Saturday August 27, 2016 @03:37PM (#12373813)
Eiffel has design by contract build in, as does D.
Re:Ask HN: Is there a programming language with embedded tes... by vram22 on Sunday August 28, 2016 @05:53AM (#12375962)
D also has unit testing built in. IIRC, they do mention a limitation or two.
Re:Ask HN: Is there a programming language with embedded tes... by piinbinary on Saturday August 27, 2016 @03:33PM (#12373803)
I'm not sure this is exactly what you are asking about, but Rust does support testing right in the language. You can add #[test] before a function to make it a test function (tests and regular functions can live together in the same file).

https://doc.rust-lang.org/book/testing.html

Re:Ask HN: Is there a programming language with embedded tes... by dougdescombaz on Saturday August 27, 2016 @02:12PM (#12373448)
Assertions in Java exist. Not really tests per se, but the closest thing I could think of.
Re:Ask HN: Is there a programming language with embedded tes... by danblick on Saturday August 27, 2016 @03:52PM (#12373882)
Look up "model checking" and see how that compares to what you're thinking about. How would you specify tests (or rather, correct program behavior) in such a language?

The languages Alloy and TLA+ come to mind. (So does Coq, which is at the other extreme of actually proving your program correct.)

Re:Ask HN: Is there a programming language with embedded tes... by alimw on Sunday August 28, 2016 @09:43AM (#12376460)
Clojure's most recent builds include "spec". http://clojure.org/guides/spec
Re:Ask HN: Is there a programming language with embedded tes... by reitanqild on Saturday August 27, 2016 @02:28PM (#12373522)
> perhaps does not provide full proof/correctness/contract support but does come with testing right out of the box, either in its implementation or philosophy?

Python has doctests.

Not sure if thats what you mean?

Re:Ask HN: Is there a programming language with embedded tes... by philippnagel on Saturday August 27, 2016 @03:31PM (#12373797)
Re:Ask HN: Is there a programming language with embedded tes... by jsli on Saturday August 27, 2016 @06:27PM (#12374440)
Yeah, Pyret!
Re:Ask HN: Is there a programming language with embedded tes... by jeff_petersen on Sunday August 28, 2016 @01:33PM (#12377428)
Came here to post just this. It is an "academic" language, designed more for teaching than for any production use, but it has a good pedigree and I've had some fun playing around with it.