comp.lang.ada
 help / color / mirror / Atom feed
* Ada aunit examples
@ 2018-04-27  4:57 Michael Hardeman
  2018-04-27  9:03 ` Felix Krause
  2018-05-10 20:39 ` Stephen Leake
  0 siblings, 2 replies; 7+ messages in thread
From: Michael Hardeman @ 2018-04-27  4:57 UTC (permalink / raw)


Hey,

Does anyone here have a good example of a project that uses AUnit?

I want to see an example of a good test structure.
What is a harness, and how is it used?
What is a test suite, and how is it used?
How do I integrate it properly into my gpr project files?

You can see the project I'm working on here. Notice there is a tests folder with plenty of tests ready to be added to a testing framework. https://github.com/MichaelAllenHardeman/bitcoin_script


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada aunit examples
  2018-04-27  4:57 Ada aunit examples Michael Hardeman
@ 2018-04-27  9:03 ` Felix Krause
  2018-04-27 16:28   ` Michael Hardeman
  2018-05-08 17:09   ` Michael Hardeman
  2018-05-10 20:39 ` Stephen Leake
  1 sibling, 2 replies; 7+ messages in thread
From: Felix Krause @ 2018-04-27  9:03 UTC (permalink / raw)


AdaYaml [1] uses AUnit.

On 2018-04-27 04:57:56 +0000, Michael Hardeman said:
> 
> I want to see an example of a good test structure.
> What is a harness, and how is it used?

It's your main executable that you call to run the tests. It 
instantiates the test runner with the suite you want to run and 
optionally sets up reporting. In AdaYaml, I have one harness per suite, 
and each enables colors for the reporting output (green / red for 
passed / failed tests). You could also do things like having one single 
harness for all suites, and then selecting the suite with a command 
line parameter.

> What is a test suite, and how is it used?

It groups a set of test cases. Since each test case can actually 
consist of multiple tests, suites are a bit superfluous for small 
projects since they introduce a hierarchy level in your test structure 
that you might not actually need.

How you use suites depends on your project. In AdaYaml, I have two 
suites: On including all test cases concerned with loading YAML data, 
and one including all test cases concerned with dumping YAML data. This 
makes sense for me since the code used for loading and dumping is 
fairly disjoint and when I change anything on the loading side, it 
suffices to run the loading test suite to check whether I broke 
anything.

Initially, I had one test suite for each component (Lexer, Parser, 
DOM-Composer), but that basically meant that each suite contained a 
single test case. This was arguably better for running only a specific 
test case, but in the end, I decided that since all tests run in under 
one second, I can simply merge them.

> How do I integrate it properly into my gpr project files?

You create a new project file that compiles your tests, for example 
project-tests.gpr (AdaYaml has yaml-tests.gpr). That makes the test 
project a child of the main project. It typically makes sense to use 
the same compiler options for the tests as you use for the main 
project, like so:

    package Compiler renames Yaml.Compiler;

If you have scenario variables in your main project that alter 
compilation behavior (e.g. for debug/release builds), this will then 
also affect the test builds. In more complex scenarios, you may need to 
access the main project's scenario variables and include different 
tests based on what optional features are enabled in your main project.


 [1]: https://github.com/yaml/AdaYaml

-- 
Regards,
Felix Krause


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada aunit examples
  2018-04-27  9:03 ` Felix Krause
@ 2018-04-27 16:28   ` Michael Hardeman
  2018-05-08 17:09   ` Michael Hardeman
  1 sibling, 0 replies; 7+ messages in thread
From: Michael Hardeman @ 2018-04-27 16:28 UTC (permalink / raw)


Thanks for your comprehensive reply Felix, I will look over the example and see what I can use for my project.

I think I will opt for a single test harness.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada aunit examples
  2018-04-27  9:03 ` Felix Krause
  2018-04-27 16:28   ` Michael Hardeman
@ 2018-05-08 17:09   ` Michael Hardeman
  2018-05-12 16:36     ` Felix Krause
  1 sibling, 1 reply; 7+ messages in thread
From: Michael Hardeman @ 2018-05-08 17:09 UTC (permalink / raw)


On Friday, April 27, 2018 at 5:03:48 AM UTC-4, Felix Krause wrote:
> AdaYaml [1] uses AUnit.
> 
> On 2018-04-27 04:57:56 +0000, Michael Hardeman said:
> > 
> > I want to see an example of a good test structure.
> > What is a harness, and how is it used?
> 
> It's your main executable that you call to run the tests. It 
> instantiates the test runner with the suite you want to run and 
> optionally sets up reporting. In AdaYaml, I have one harness per suite, 
> and each enables colors for the reporting output (green / red for 
> passed / failed tests). You could also do things like having one single 
> harness for all suites, and then selecting the suite with a command 
> line parameter.
> 
> > What is a test suite, and how is it used?
> 
> It groups a set of test cases. Since each test case can actually 
> consist of multiple tests, suites are a bit superfluous for small 
> projects since they introduce a hierarchy level in your test structure 
> that you might not actually need.
> 
> How you use suites depends on your project. In AdaYaml, I have two 
> suites: On including all test cases concerned with loading YAML data, 
> and one including all test cases concerned with dumping YAML data. This 
> makes sense for me since the code used for loading and dumping is 
> fairly disjoint and when I change anything on the loading side, it 
> suffices to run the loading test suite to check whether I broke 
> anything.
> 
> Initially, I had one test suite for each component (Lexer, Parser, 
> DOM-Composer), but that basically meant that each suite contained a 
> single test case. This was arguably better for running only a specific 
> test case, but in the end, I decided that since all tests run in under 
> one second, I can simply merge them.
> 
> > How do I integrate it properly into my gpr project files?
> 
> You create a new project file that compiles your tests, for example 
> project-tests.gpr (AdaYaml has yaml-tests.gpr). That makes the test 
> project a child of the main project. It typically makes sense to use 
> the same compiler options for the tests as you use for the main 
> project, like so:
> 
>     package Compiler renames Yaml.Compiler;
> 
> If you have scenario variables in your main project that alter 
> compilation behavior (e.g. for debug/release builds), this will then 
> also affect the test builds. In more complex scenarios, you may need to 
> access the main project's scenario variables and include different 
> tests based on what optional features are enabled in your main project.
> 
> 
>  [1]: https://github.com/yaml/AdaYaml
> 
> -- 
> Regards,
> Felix Krause

Hey Felix, I'm in the process of restructuring my project to add AUnit, based on your example, and I'm confused by this line.
I in your code, what does this line do?

https://github.com/yaml/AdaYaml/blob/develop/test/src/yaml-lexer-buffering_test.adb#L28


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada aunit examples
  2018-04-27  4:57 Ada aunit examples Michael Hardeman
  2018-04-27  9:03 ` Felix Krause
@ 2018-05-10 20:39 ` Stephen Leake
  1 sibling, 0 replies; 7+ messages in thread
From: Stephen Leake @ 2018-05-10 20:39 UTC (permalink / raw)


On Thursday, April 26, 2018 at 11:57:58 PM UTC-5, Michael Hardeman wrote:
> Hey,
> 
> Does anyone here have a good example of a project that uses AUnit?
> 
> I want to see an example of a good test structure.
> What is a harness, and how is it used?
> What is a test suite, and how is it used?
> How do I integrate it properly into my gpr project files?
> 
> You can see the project I'm working on here. Notice there is a tests folder with plenty of tests ready to be added to a testing framework. https://github.com/MichaelAllenHardeman/bitcoin_script

SAL (http://www.stephe-leake.org/ada/sal.html) has AUnit tests. It also has an aunit extension package Checks that makes it easier to write AUnit tests.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada aunit examples
  2018-05-08 17:09   ` Michael Hardeman
@ 2018-05-12 16:36     ` Felix Krause
  2018-07-05 19:03       ` Michael Hardeman
  0 siblings, 1 reply; 7+ messages in thread
From: Felix Krause @ 2018-05-12 16:36 UTC (permalink / raw)


On 2018-05-08 17:09:28 +0000, Michael Hardeman said:
> 
> Hey Felix, I'm in the process of restructuring my project to add AUnit, 
> based on your example, and I'm confused by this line.
> I in your code, what does this line do?
> 
> https://github.com/yaml/AdaYaml/blob/develop/test/src/yaml-lexer-buffering_test.adb#L28 
> 

Nothing to worry about. AdaYaml uses reference-counted strings which 
are allocated from a custom memory pool (which adds the reference 
count), and this line initialises that pool.

-- 
Regards,
Felix Krause

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Ada aunit examples
  2018-05-12 16:36     ` Felix Krause
@ 2018-07-05 19:03       ` Michael Hardeman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Hardeman @ 2018-07-05 19:03 UTC (permalink / raw)


Hey Felix,

I've finished converting everything to use aunit, and wrote a whole heap of new tests. I've even almost got gcov working which would be a good way to track and improve my code quality.

I would appreciate it greatly if you could give my project a once over and maybe a light code review. There were quite a few tricky things in the project setup and some things I didn't quite understand but could get working with some tinkering.

On Saturday, May 12, 2018 at 12:36:48 PM UTC-4, Felix Krause wrote:
> On 2018-05-08 17:09:28 +0000, Michael Hardeman said:
> > 
> > Hey Felix, I'm in the process of restructuring my project to add AUnit, 
> > based on your example, and I'm confused by this line.
> > I in your code, what does this line do?
> > 
> > https://github.com/yaml/AdaYaml/blob/develop/test/src/yaml-lexer-buffering_test.adb#L28 
> > 
> 
> Nothing to worry about. AdaYaml uses reference-counted strings which 
> are allocated from a custom memory pool (which adds the reference 
> count), and this line initialises that pool.
> 
> -- 
> Regards,
> Felix Krause


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-07-05 19:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-27  4:57 Ada aunit examples Michael Hardeman
2018-04-27  9:03 ` Felix Krause
2018-04-27 16:28   ` Michael Hardeman
2018-05-08 17:09   ` Michael Hardeman
2018-05-12 16:36     ` Felix Krause
2018-07-05 19:03       ` Michael Hardeman
2018-05-10 20:39 ` Stephen Leake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox