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

Creating a parser to transform the Matlab documentation into a structure #20

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Added error messages in unit test
gaspardcereza committed Jul 3, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit e6e3348d2e57e64231626d6d42c93aa32989caa3
9 changes: 6 additions & 3 deletions tests/test_parse_doc.m
Original file line number Diff line number Diff line change
@@ -8,12 +8,15 @@
cd('../parser')
Copy link

@gab-berest gab-berest Jul 2, 2020

Choose a reason for hiding this comment

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

There will be an error if the function is run from another directory than the one tested (and in Matlab, it is possible to run a script or function from a different directory). Maybe you should check with a pwd function end extrapolate the correct way to get to the place you want. You could also check this link to know more about finding an item location in Matlab:
https://www.mathworks.com/help/matlab/ref/which.html
This way your code could be more robust.

Copy link
Member

Choose a reason for hiding this comment

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

I think you should consider removing this line entirely and make the code work whether this is called from anywhere.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes that's something I why trying to do but I could only find the path to the function using which if I was already in the right folder (not really useful in our case...). One solution would be to add helpDocMd/parser/ to the Matlab path but It would also require to know the full path toward it. @po09i do you know how this is usually done with unit testing ?

Choose a reason for hiding this comment

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

The which command in Matlab does this. It returns the absolute path of the file you asked. See the link I added in my previous comment.

Copy link
Member

Choose a reason for hiding this comment

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

There should be a startup.m script like the one in shimming-toolbox which adds all the source files to the Matlab path. This script would be launched when running the tests. So my point of view is you should assume all of helpDocMd is on the Matlab path. If it is not yet created in this repo, I think you should create it.

docStruct = parse_doc('parse_doc.m');

assert(isstruct(docStruct)) % Check if docStruct is indeed a structure
% Check if docStruct is indeed a structure
assert(isstruct(docStruct), 'docStruct is not a structure')

% Make sure every input/output name matches a description
if docStruct.inputs.names ~= ''
assert(length(docStruct.inputs.names) == length(docStruct.inputs.description));
assert(length(docStruct.inputs.names) == length(docStruct.inputs.description),...
'The number of input names does not match the number of descriptions');
end
if docStruct.outputs.names ~= ''
assert(length(docStruct.outputs.names) == length(docStruct.outputs.description));
assert(length(docStruct.outputs.names) == length(docStruct.outputs.description),...
'The number of output names does not match the number of descriptions');
end