Skip to content

Latest commit

 

History

History

aunit-examples

AUnit examples

Ada project Directory aunit-examples\ contains Ada code examples from the GitHub project AdaCore/aunit.

We made the following changes to the original AdaCore/aunit code examples:

  • We introduce a parent project file Makefile.inc which gathers all tool definitions and takes care of different settings for 3 environments: MSYS2, Windows and Unix.
  • We require the two environment variables GNAT_HOME and MSYS_HOME to be defined when working in the MSYS2 and Windows environments (behavior is unchanged under Unix).

calculator Example

We build this code example using the make.exe build tool (project file Makefile depends on parent file Makefile.inc).

> where make
C:\opt\msys64\usr\bin\make.exe
 
> make
"C:/opt/GNAT/2021/bin/gprbuild.exe" -p -f -Pharness
Setup
   [mkdir]        object directory for project Harness
Compile
   [Ada]          test_calculator.adb
   [...]
   [Ada]          operations-subtraction_test_fixture.adb
Build Libraries
   [gprlib]       testlib.lexch
   [archive]      libtestlib.a
   [index]        libtestlib.a
Bind
   [gprbind]      test_calculator.bexch
   [Ada]          test_calculator.ali
Link
   [link]         test_calculator.adb
 
> test_calculator.exe

OK Test Stack.Push
OK Test Stack.Pop
OK Test Stack.Length
OK Test Stack.Top
[...]
Total Tests Run:   14
Successful Tests:  12
Failed Assertions: 2
Unexpected Errors: 0

failures Example

Project failures consists of 3 sets of files:

> make
"C:/opt/GNAT/2021/bin/gprbuild.exe" -p -Pharness
Setup
   [mkdir]        object directory for project TestLib
   [mkdir]        object directory for project Harness
Compile
   [Ada]          test_math.adb
   [Ada]          math.adb
   [Ada]          math_suite.adb
   [Ada]          math-test.adb
Build Libraries
   [gprlib]       testlib.lexch
   [archive]      libtestlib.a
   [index]        libtestlib.a
Bind
   [gprbind]      test_math.bexch
   [Ada]          test_math.ali
Link
   [link]         test_math.adb
 
> test_math.exe
 
OK Test addition
OK Test subtraction
 
FAIL Test addition (failure expected)
    Test should fail this assertion, as 5+3 /= 9
    at math-test.adb:29
 
ERROR Test addition (error expected)
    CONSTRAINT_ERROR
    Exception Message: math.adb:8 overflow check failed
    Traceback:
        [%USERPROFILE%\workspace-perso\ada-examples\aunit-examples\failures\test_math.exe]
        0x7ff7f85626f2 Math."+" at math.adb:8
        0x7ff7f8561e98 Math.Test.Test_Addition_Error at math-test.adb:37
        0x7ff7f856210a Math_Suite.Caller.Run_Test at aunit-test_caller.adb:96
        0x7ff7f85664a5 aunit__assertions__TtestCFD at ???
        0x7ff7f8566767 aunit__assertions__TtestCFD at ???
        0x7ff7f8569679 aunit__assertions__TtestCFD at ???
        0x7ff7f8566249 aunit__assertions__TtestCFD at ???
        0x7ff7f85615e3 Test_Math at aunit-run.adb:88
        0x7ff7f8561d00 Main at b__test_math.adb:399
        0x7ff7f85613af __tmainCRTStartup at crtexe.c:321
        0x7ff7f85614e4 mainCRTStartup at crtexe.c:202
        [C:\WINDOWS\System32\KERNEL32.DLL]
        0x7ffc4c7d7032
        [C:\WINDOWS\SYSTEM32\ntdll.dll]
        0x7ffc4df4264f


Total Tests Run:   4
Successful Tests:  2
Failed Assertions: 1
Unexpected Errors: 1

liskov Example

wip

> make
"C:/opt/GNAT/2021/bin/gprbuild.exe" -p -Pharness
Setup
   [mkdir]        object directory for project TestLib
   [mkdir]        object directory for project Harness
Compile
   [Ada]          test_liskov.adb
   [...]
   [Ada]          square-tests-suite_liskov.adb
   [Ada]          shape-tests.adb
Build Libraries
   [gprlib]       testlib.lexch
   [archive]      libtestlib.a
   [index]        libtestlib.a
Bind
   [gprbind]      test_liskov.bexch
   [Ada]          test_liskov.ali
Link
   [link]         test_liskov.adb
 
> test_liskov.exe

OK Rectangle : Test width
OK Rectangle : Test height
OK Rectangle : Test area
OK Square : Test width
OK Square : Test height
OK Square : Test area
OK Square as Rectangle (liskov) : Test width
OK Square as Rectangle (liskov) : Test height

FAIL Square as Rectangle (liskov) : Test area
    Wrong area returned for object rectangle
    at rectangle-tests.adb:28

Total Tests Run:   9
Successful Tests:  8
Failed Assertions: 1
Unexpected Errors: 0

mics/May 2024