Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » packages » check
next | previous | forward | backward | up | index | toc

check -- perform tests of a package

Description

It is important for package authors to provide tests to ensure that the package is functioning properly. One provides tests using the TEST function following the beginDocumentation call in the source of the package.

Optionally, one can store all tests in a tests.m2 file under the auxiliary subdirectory of the package and load the file from the main package source file.

For example, to run the tests for the FirstPackage package, use:

i1 : needsPackage "FirstPackage" 

o1 = FirstPackage

o1 : Package
i2 : check_1 FirstPackage
 -- warning: reloading FirstPackage; recreate instances of types from this package
 -- capturing check(1, "FirstPackage")        -- .150237s elapsed
i3 : check FirstPackage
 -- capturing check(0, "FirstPackage")        -- .146395s elapsed
 -- capturing check(1, "FirstPackage")        -- .147026s elapsed

Alternatively, if the package is installed somewhere accessible, one can do the following.

i4 : check_1 "FirstPackage"
 -- capturing check(1, "FirstPackage")        -- .146232s elapsed
i5 : check "FirstPackage"
 -- capturing check(0, "FirstPackage")        -- .146757s elapsed
 -- capturing check(1, "FirstPackage")        -- .146798s elapsed

A TestInput object (or a list of such objects) can also be run directly.

i6 : tests(1, "FirstPackage")

o6 = TestInput[/usr/share/Macaulay2/FirstPackage.m2:58:5-60:3]

o6 : TestInput
i7 : check oo
 -- capturing check(1, "FirstPackage")        -- .146523s elapsed
i8 : tests "FirstPackage"

o8 = {0 => TestInput[/usr/share/Macaulay2/FirstPackage.m2:54:5-56:3]}
     {1 => TestInput[/usr/share/Macaulay2/FirstPackage.m2:58:5-60:3]}

o8 : NumberedVerticalList
i9 : check oo
 -- capturing check(0, "FirstPackage")        -- .146579s elapsed
 -- capturing check(1, "FirstPackage")        -- .146453s elapsed

If only an integer is passed as an argument, then the test with that index from the last call to tests is run.

i10 : tests "FirstPackage"

o10 = {0 => TestInput[/usr/share/Macaulay2/FirstPackage.m2:54:5-56:3]}
      {1 => TestInput[/usr/share/Macaulay2/FirstPackage.m2:58:5-60:3]}

o10 : NumberedVerticalList
i11 : check 1
 -- capturing check(1, "FirstPackage")        -- .146138s elapsed

Caveat

Currently, if the package was only partially loaded because the documentation was obtainable from a database (see beginDocumentation), then the package will be reloaded, this time completely, to ensure that all tests are considered; this may affect user objects of types declared by the package, as they may be not usable by the new instance of the package. In a future version, either the tests and the documentation will both be cached, or neither will.

See also

Ways to use check:

  • check(List)
  • check(List,Package)
  • check(List,String)
  • check(Package)
  • check(String)
  • check(TestInput)
  • check(ZZ)
  • check(ZZ,Package)
  • check(ZZ,String)

For the programmer

The object check is a method function with options.


The source of this document is in /build/reproducible-path/macaulay2-1.25.06+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/check-doc.m2:125:0.