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

Find tests in .oct files #179

Merged
merged 5 commits into from
Jan 22, 2019
Merged

Find tests in .oct files #179

merged 5 commits into from
Jan 22, 2019

Conversation

cbm755
Copy link
Collaborator

@cbm755 cbm755 commented Mar 10, 2018

"help meh.oct" doesn't work so strip the ".oct" if specified. This
makes doctest . work. If both meh.oct and meh.m are present,
"help meh" will get the .oct file; this does the same. doctest meh.m
will explicitly test the .m file. This may work for mex files although
I haven't tested that.

@cbm755
Copy link
Collaborator Author

cbm755 commented Mar 10, 2018

@mtmiller This seems to work.

I have not added tests because I don't think we want compiled code in this project.

Re: mex files: At least in Matlab, I think they are documented in a separate m-file (https://www.mathworks.com/help/matlab/matlab_external/using-help-files-with-mex-files.html). I believe that would work with this fix, but have not tested.

"help meh.oct" doesn't work so strip the ".oct" if specified.  This
makes `doctest .` work.  If both meh.oct and meh.m are present,
"help meh" will get the .oct file; this does the same.  `doctest meh.m`
will explicitly test the .m file.  This may work for mex files although
I haven't tested that.

Fixes #178.
@cbm755 cbm755 force-pushed the dot_finds_oct_files branch from 74197e5 to d1e4466 Compare March 10, 2018 22:45
@mtmiller
Copy link
Collaborator

mtmiller commented Mar 11, 2018

Yeah, works for me with my limited testing of directories of oct files.

This doesn't fix all of #178, though. It should also be possible to get a list of secondary functions defined in an oct file that has multiple DEFUNs, each with their own doc strings.

cbm755 added 2 commits March 11, 2018 19:36
`doctest foo.oct` will test the function `foo` itself as well as any
other functions defined in `foo.oct` and exposted in the autoload map.
On the other hand, `doctest foo` will test only the function `foo`.

Fixes #178.
type = 'octfile';
elseif (exist (what) == 3) % .oct/.mex
[~, what, ~] = fileparts (what); % strip extension if present
type = 'function'; % then access like any function
Copy link
Collaborator Author

@cbm755 cbm755 Mar 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block (% .oct/.mex) matches:

  1. doctest foo (rather than doctest foo.oct). I don't think its necessary for this (a later block will DTRT) but it doesn't hurt, and maybe makes clearer the expected difference between doctest foo.oct and doctest foo.
  2. doctest bar.mex and doctest bar: I haven't tested any .mex stuff yet.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like this distinction between doctest func and doctest func.oct. I didn't see a clean way to do it when I was making my changes.

@cbm755
Copy link
Collaborator Author

cbm755 commented Mar 12, 2018

@mtmiller what do you think?

I wonder if we should make some test cases for this: they could be optional and not part of the usual test run (as they need to be compiled) but they'd be there to help anyone refactoring this code in the future.

@catch22
Copy link
Collaborator

catch22 commented Mar 12, 2018

I agree that it would be good to have test cases that are run as part of the test suite on Travis, especially since the rules regarding which tests are picked up (and in which order) seem to be a bit subtle from what I understand.

Copy link
Collaborator

@mtmiller mtmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall I think this is a much better approach than my recursive hack.

I think we can further improve it to also allow doctesting a .oct file anywhere in the load path, either like doctest foo.oct or doctest /path/to/foo.oct.

Thanks for working on this!

type = 'octfile';
elseif (exist (what) == 3) % .oct/.mex
[~, what, ~] = fileparts (what); % strip extension if present
type = 'function'; % then access like any function
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I like this distinction between doctest func and doctest func.oct. I didn't see a clean way to do it when I was making my changes.

@@ -135,6 +141,8 @@
targets = [target];
elseif strcmp(type, 'class')
targets = collect_targets_class(what, depth);
elseif strcmp (type, 'octfile')
targets = collect_targets_octfile (what, depth);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is way nicer than my recursive approach. I didn't read enough of the code to see how to build up the targets list, I just saw the way directories were handled and followed that logic. I like this a lot.

targets = [target];

% octfile may have many fcns in it: find them using the autoload map
A = fullfile (pwd, file);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only works in the limited case where foo.oct is in the current working directory. IOW, exactly when it was called from doctest somedir and doctest already did a chdir. What if we use which or file_in_loadpath to get the full file name of [basename '.oct']?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just use the match-only-the-filename approach from your PR? Maybe that's good enough for now. Do you think many people have a generic utils.oct or similar lying around if different directories?

There is some overlap here with the discussion in #87 about classes and whether only "locally" defined methods should be tested or all methods (such as those from superclasses defined elsewhere).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably good enough for a start if you'd rather stay simple and just use the basename. I really don't think non-developers have their own personal .oct files floating around. The much more likely case of the same .oct file is multiple copies in different directories, maybe with a pkg load and with a manual addpath, which should be ok.

I searched the entire Debian archive for any files ending with .oct, and I found 226 unique file names, no duplicates, which doesn't say anything about third-party or personal projects, but at least no well-known projects are using names like common.oct or main.oct.

I = find (strcmp (files, A));
if (~ isempty (I))
% indicate that octfile has other fcns, and indent those targets
targets(1).name = [targets(1).name ':'];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I like the idea of labeling the function with its .oct file.

User could be testing any .oct file in the load path, so remove pwd.
@cbm755
Copy link
Collaborator Author

cbm755 commented Mar 19, 2018

@mtmiller I've merged your changes: are you happy with 6eb5deb?

@mtmiller
Copy link
Collaborator

Hey, sorry if you were waiting on me. This fell off my radar, but looks good to me.

@cbm755
Copy link
Collaborator Author

cbm755 commented Jan 22, 2019

Fell off mine too, I'll merge this for now.

Testing of this is the other PR, still not sure about how we want organize that, esp. for packagers.

@cbm755 cbm755 merged commit 58d89d6 into master Jan 22, 2019
@cbm755 cbm755 deleted the dot_finds_oct_files branch January 22, 2019 19:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants