From 3afa02b88db297d07f61188640437af090d62e47 Mon Sep 17 00:00:00 2001 From: Oliver Heimlich Date: Fri, 13 Nov 2015 22:44:43 +0100 Subject: [PATCH] Added unit tests for octave-api --- .travis.yml | 4 +- client-api/Octave/.gitignore | 2 +- client-api/Octave/Makefile | 27 ++++++++++- client-api/Octave/inst/+vibes/axisAuto.m | 5 ++ client-api/Octave/inst/+vibes/axisLabels.m | 8 ++++ client-api/Octave/inst/+vibes/beginDrawing.m | 10 ++++ client-api/Octave/inst/+vibes/drawBox.m | 50 ++++++++++++++++++++ client-api/Octave/inst/+vibes/drawLine.m | 13 +++++ client-api/Octave/inst/+vibes/endDrawing.m | 5 ++ client-api/Octave/inst/+vibes/newFigure.m | 8 ++++ 10 files changed, 127 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 135bf5e..27b3ce7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -15,7 +15,7 @@ install: # 32 bit compatibility (since CMake is a 32 bit bin) - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -qq libc6:i386; fi # Install Octave for test of client API - - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -qq octave liboctave-dev; fi + - if [ $TRAVIS_OS_NAME == linux ]; then sudo apt-get install -qq octave liboctave-dev libmpfr-dev; fi # Install CMake bin (32 bit) - if [ $TRAVIS_OS_NAME == linux ]; then wget --no-check-certificate -P /tmp http://www.cmake.org/files/v2.8/cmake-2.8.12.1-Linux-i386.sh; fi - if [ $TRAVIS_OS_NAME == linux ]; then chmod +rx /tmp/cmake-2.8.12.1-Linux-i386.sh; fi @@ -29,7 +29,7 @@ before_script: script: - make -C viewer/build - make -C client-api/Octave - - if [ $TRAVIS_OS_NAME == linux ]; then make -C client-api/Octave install; fi + - if [ $TRAVIS_OS_NAME == linux ]; then make -C client-api/Octave check; fi after_success: - if [ $TRAVIS_OS_NAME == linux ]; then make -C client-api/Octave html; fi diff --git a/client-api/Octave/.gitignore b/client-api/Octave/.gitignore index 1f85430..91870c9 100644 --- a/client-api/Octave/.gitignore +++ b/client-api/Octave/.gitignore @@ -1,6 +1,6 @@ vibes-*.tar.gz vibes-bundle/** vibes-html/** -fntest.log +fntests.log octave-* diff --git a/client-api/Octave/Makefile b/client-api/Octave/Makefile index 8257306..e16e903 100644 --- a/client-api/Octave/Makefile +++ b/client-api/Octave/Makefile @@ -105,16 +105,39 @@ md5: $(RELEASE_TARBALL) $(HTML_TARBALL) ## ## Testing Process ## -## Interactive shell with the package installed and loaded +## Interactive shell with the package installed and loaded / +## Non-interactive processing of integrated unit tests ## -.PHONY: run +.PHONY: run check +PUBLIC_FUNCTIONS = $(patsubst inst/%.m,%,$(wildcard inst/+vibes/*.m)) run: $(INSTALLED_PACKAGE) @echo "Run GNU Octave with the development version of the package" @$(OCTAVE) --no-gui --silent --eval "pkg load $(PACKAGE)" --persist @echo +check: $(INSTALLED_PACKAGE) + @echo "Testing package in GNU Octave ..." + @# Make sure that the interval package is present, some tests depend on this + @$(OCTAVE) --no-gui --silent \ + --eval "try;" \ + --eval "temp = pkg ('describe', 'interval');" \ + --eval "catch;" \ + --eval "pkg ('install', '-forge', 'interval');" \ + --eval "end_try_catch;" + @rm -f ~/.vibes.json + @$(OCTAVE) --no-gui --silent \ + --eval "pkg load $(PACKAGE);" \ + --eval "success = true;" \ + --eval "targets = strsplit ('$(PUBLIC_FUNCTIONS)', ' ');" \ + --eval "for target = targets;" \ + --eval "[n, nmax] = test (target{1}, 'verbose');" \ + --eval "success &= (n == nmax);" \ + --eval "endfor;" \ + --eval "exit (not (success));" + @cat ~/.vibes.json + ## ## Cleanup ## diff --git a/client-api/Octave/inst/+vibes/axisAuto.m b/client-api/Octave/inst/+vibes/axisAuto.m index 81653fb..48cd74d 100644 --- a/client-api/Octave/inst/+vibes/axisAuto.m +++ b/client-api/Octave/inst/+vibes/axisAuto.m @@ -30,3 +30,8 @@ function axisAuto () __vibes__ ('axisAuto'); endfunction + +%!test +%! vibes.beginDrawing +%! vibes.axisAuto +%! vibes.endDrawing diff --git a/client-api/Octave/inst/+vibes/axisLabels.m b/client-api/Octave/inst/+vibes/axisLabels.m index e02135b..acf33e2 100644 --- a/client-api/Octave/inst/+vibes/axisLabels.m +++ b/client-api/Octave/inst/+vibes/axisLabels.m @@ -35,3 +35,11 @@ function axisLabels (varargin) __vibes__ ('axisLabels', varargin{:}); endfunction + +%!shared +%! vibes.beginDrawing +%!test vibes.axisLabels ('x', 'y', 'z') +%!test vibes.axisLabels ({'x', 'y', 'z'}) +%!test vibes.axisLabels ({'a', 'b', 'c'}, 'alphabet') +%!shared +%! vibes.endDrawing diff --git a/client-api/Octave/inst/+vibes/beginDrawing.m b/client-api/Octave/inst/+vibes/beginDrawing.m index f01dbbc..aa84dbb 100644 --- a/client-api/Octave/inst/+vibes/beginDrawing.m +++ b/client-api/Octave/inst/+vibes/beginDrawing.m @@ -60,3 +60,13 @@ function beginDrawing (filename) endswitch endfunction + +%!test +%! vibes.beginDrawing +%! vibes.endDrawing +%!warning vibes.beginDrawing; vibes.beginDrawing; vibes.endDrawing +%!test +%! vibes.beginDrawing ('.vibes-custom.json') +%! assert (exist ('.vibes-custom.json', 'file')) +%! vibes.endDrawing +%! delete ('.vibes-custom.json') diff --git a/client-api/Octave/inst/+vibes/drawBox.m b/client-api/Octave/inst/+vibes/drawBox.m index 5987248..bf59465 100644 --- a/client-api/Octave/inst/+vibes/drawBox.m +++ b/client-api/Octave/inst/+vibes/drawBox.m @@ -64,3 +64,53 @@ function drawBox (varargin) __vibes__ ('drawBox', varargin{:}); endfunction + +%!shared x,y,z +%! vibes.beginDrawing +%! x = [ 0 2 ; ... +%! 7 22 ]; +%! y = [ 1 2 3 4 ; ... +%! 2 3 4 5 ]; +%! z = [ 1 2 ; ... +%! 3 4 ; ... +%! 5 6 ; ... +%! 7 8 ]; +%!test vibes.drawBox (x) +%!test vibes.drawBox (y) +%!test vibes.drawBox (z) +%!test vibes.drawBox (-1, 0, 1, 2) +%!test vibes.drawBox (-1, 0, 1, 2, 4, 5) +%!shared +%! vibes.endDrawing + +%!shared ix,iy,iz,dx,dy,dz,rx,ry,rz +%! pkg load interval +%! vibes.beginDrawing +%! x = [ 0 2 ; ... +%! 7 22 ]; +%! y = [ 1 2 3 4 ; ... +%! 2 3 4 5 ]; +%! z = [ 1 2 ; ... +%! 3 4 ; ... +%! 5 6 ; ... +%! 7 8 ]; +%! ix = infsup (x) +%! iy = infsup (y) +%! iz = infsup (z) +%! dx = infsupdec (x) +%! dy = infsupdec (y) +%! dz = infsupdec (z) +%! rx = infsup (x, x + 100) +%! ry = infsup (y, y + 100) +%! rz = infsup (z, z + 100) +%!test vibes.drawBox (ix) +%!test vibes.drawBox (iy) +%!test vibes.drawBox (iz) +%!test vibes.drawBox (dx) +%!test vibes.drawBox (dy) +%!test vibes.drawBox (dz) +%!test vibes.drawBox (rx) +%!test vibes.drawBox (ry) +%!test vibes.drawBox (rz) +%!shared +%! vibes.endDrawing diff --git a/client-api/Octave/inst/+vibes/drawLine.m b/client-api/Octave/inst/+vibes/drawLine.m index 5aaa8ec..30b3df1 100644 --- a/client-api/Octave/inst/+vibes/drawLine.m +++ b/client-api/Octave/inst/+vibes/drawLine.m @@ -38,3 +38,16 @@ function drawLine (varargin) __vibes__ ('drawLine', varargin{:}); endfunction + +%!shared x +%! vibes.beginDrawing +%! x = [ 0 0 ; ... +%! 1 1 ; ... +%! 2 2 ]; +%!test vibes.drawLine (x) +%!test vibes.drawLine (x, 'figure', 'foo') +%!test vibes.drawLine (x, 'red') +%!test vibes.drawLine (x, 'figure', 'bar', 'blue') +%!test vibes.drawLine (x, 'green', 'figure', 'baz') +%!shared +%! vibes.endDrawing diff --git a/client-api/Octave/inst/+vibes/endDrawing.m b/client-api/Octave/inst/+vibes/endDrawing.m index f6b1df7..95f3eaf 100644 --- a/client-api/Octave/inst/+vibes/endDrawing.m +++ b/client-api/Octave/inst/+vibes/endDrawing.m @@ -36,3 +36,8 @@ function endDrawing () __vibes__ ('endDrawing'); endfunction + +%!test +%! vibes.beginDrawing +%! vibes.endDrawing +%!warning vibes.endDrawing diff --git a/client-api/Octave/inst/+vibes/newFigure.m b/client-api/Octave/inst/+vibes/newFigure.m index 3dfc489..8ef61ee 100644 --- a/client-api/Octave/inst/+vibes/newFigure.m +++ b/client-api/Octave/inst/+vibes/newFigure.m @@ -34,3 +34,11 @@ function newFigure (name) endswitch endfunction + +%!shared +%! vibes.beginDrawing +%!test vibes.newFigure +%!test vibes.newFigure ('Foobar') +%!test vibes.newFigure +%!shared +%! vibes.endDrawing