Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctest does not work properly with namespaces #230

Open
skycaptain opened this issue Sep 26, 2019 · 3 comments
Open

Doctest does not work properly with namespaces #230

skycaptain opened this issue Sep 26, 2019 · 3 comments

Comments

@skycaptain
Copy link

Calling doctest directly on a file works fine:

>> doctest src/matlab/+myPackage/getVersion.m
Doctest v0.7.0+: this is Free Software without warranty, see source.

src/matlab/+myPackage/getVersion.m ...................... PASS    2/2   

Summary:

   PASS    2/2   

1/1 targets passed, 0 without tests.

However, when being called on a parent folder doctest suddenly does not find the tests:

>> doctest src/matlab/+myPackage -nonrecursive
Doctest v0.7.0+: this is Free Software without warranty, see source.

src/matlab/+myPackage/
  getVersion.m ......................................... NO TESTS

Summary:

   PASS    0/0   

1/1 targets passed, 1 without tests.

I'm using Matlab and the latest octave-doctest from master:

MATLAB Version: 9.7.0.1190202 (R2019b)
Operating System: Mac OS X  Version: 10.14.6 Build: 18G95 
@skycaptain skycaptain changed the title Doctest does not find test with folder passed Doctest does not find test within folder Sep 26, 2019
@skycaptain
Copy link
Author

I expected this to be the case although, the issue is the namespacing of Matlab, which is used here. In the end, doctest calls help on each file. However, when being called on a file its path (src/matlab/+myPackage/getVersion.m) gets passed to extract_docstring; when being called on a folder, only the function name (getVersion) is being passed. When using namespaces help expects the full namespace path, i.e. myPackage.getVersion. Also, stupid help does not raise an error when being called on an unknown function; it just returns an empty char array.

@cbm755
Copy link
Collaborator

cbm755 commented Sep 30, 2019

Nice sleuthing! As far as I know, no one has thought about how doctest interacts with +namespace directories.

Namespaces are also now supported on Octave as well so probably there are related or even the same bugs in Octave.

I think doctest +apkg should test

  1. +apkg/Contents.m (help apkg)
  2. everything in +apkg/.
  3. perhaps not +apkg/+subpkg, perhaps depending on -nonrecursive flag.
  4. perhaps not +pkg/private (?)
  5. doctest apkg does not precisely need to be the same as doctest +apkg: this is like doctest @logical versus doctest logical #196 and classes: test both @foo/foo and foo only for classdef #197.

I'm not sure about what should happen with +apkg/subdir/...: I don't see anything about that in Matlab's docs. Maybe we should just traverse whatever Matlab gives us from what('+apkg') and not mess around with dir +apkg?

@cbm755
Copy link
Collaborator

cbm755 commented Sep 30, 2019

I'd be happy to review PRs about this. My rough thoughts:

  1. there could be type = 'package' detected at the top of doctest_collect.
  2. maybe there could be another block a bit like this one:
% Deal with directories
if (strcmp(type, 'dir'))

@cbm755 cbm755 added this to the 0.9.0 milestone Sep 30, 2019
@cbm755 cbm755 changed the title Doctest does not find test within folder Doctest does not work properly with namespaces Sep 30, 2019
@cbm755 cbm755 modified the milestones: 0.9.0, 1.0.0 Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants