-
Notifications
You must be signed in to change notification settings - Fork 167
change parse_args_test to be more automated. #1023
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
Merged
+169
−60
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
77eec34
change parse_args_test to be more automated.
nancycollins 224f8c2
remove older version of test.
nancycollins 7da4676
added more tests for strings with stranger characters in them.
nancycollins 16e3cd9
fixed test program to address review comments, avoid literal backslas…
nancycollins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,90 +1,201 @@ | ||
| ! DART software - Copyright UCAR. This open source software is provided | ||
| ! by UCAR, "as is", without charge, subject to all terms of use at | ||
| ! http://www.image.ucar.edu/DAReS/DART/DART_download | ||
| ! | ||
|
|
||
| ! this test reads stdin. to automate it, run it with: | ||
| ! cat bob | ./parse_args_test | ||
| ! or | ||
| ! ./parse_args_test < bob | ||
| ! | ||
| ! where the file bob contains one line per test with arguments to be parsed. | ||
|
|
||
| program parse_args_test | ||
|
|
||
| use utilities_mod, only : initialize_utilities, finalize_utilities, & | ||
| register_module, error_handler, E_ERR, E_MSG | ||
| use utilities_mod, only : initialize_utilities, finalize_utilities | ||
| use parse_args_mod, only : get_args_from_string, get_name_val_pairs_from_string | ||
|
|
||
| implicit none | ||
| use test ! fortran-testanything | ||
|
|
||
| ! version controlled file description for error handling, do not edit | ||
| character(len=*), parameter :: source = "parse_args_test.f90" | ||
| character(len=*), parameter :: revision = "" | ||
| character(len=*), parameter :: revdate = "" | ||
| implicit none | ||
|
|
||
| integer :: iunit = 5 | ||
| integer :: ierr, nargs, i | ||
| integer, parameter :: MAXVALS = 100 | ||
| integer :: nargs | ||
| character(len=512) :: nextline | ||
| character(len=64) :: args(100) | ||
| character(len=64) :: names(100) | ||
| character(len=64) :: vals(100) | ||
| character(len=64) :: args(MAXVALS) | ||
| character(len=64) :: names(MAXVALS) | ||
| character(len=64) :: vals(MAXVALS) | ||
| logical :: continue_line | ||
|
|
||
| character(len=20) :: testnum | ||
|
|
||
| ! the ascii code for the backslash character is 92. | ||
| character(len=1), parameter :: BACKSLASH = ACHAR(92) | ||
|
|
||
| !---------------------------------------------------------------------- | ||
|
|
||
| ! main code here | ||
|
|
||
| ! initialize the dart libs | ||
| call initialize_utilities('parse_args_test') | ||
| call initialize_utilities('parse_args_test', standalone_program=.true.) | ||
|
|
||
| ! this count should match the number of tests expected to be | ||
| ! executed if the test program runs to completion. | ||
| call plan(57) | ||
|
|
||
| ! parse tests - divide the blank-separated words on a line | ||
| ! into individual words. note no interpretation of the | ||
| ! contents is expected - the returns are always strings. | ||
|
|
||
| testnum = 'test 1' | ||
| call resetvals() | ||
| nextline = 'one two three' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 3), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'one'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == 'two'), trim(testnum)//', arg 2') | ||
| call ok((args(3) == 'three'), trim(testnum)//', arg 3') | ||
| call ok((args(4) == ''), trim(testnum)//', arg 4') | ||
|
|
||
|
|
||
| print *, 'enter lines with words separated by blanks.' | ||
| print *, '(enter control-D to end)' | ||
| testnum = 'test 2' | ||
| call resetvals() | ||
| nextline = ' one two three ' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 3), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'one'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == 'two'), trim(testnum)//', arg 2') | ||
| call ok((args(3) == 'three'), trim(testnum)//', arg 3') | ||
| call ok((args(4) == ''), trim(testnum)//', arg 4') | ||
|
|
||
| GETMORE : do | ||
| read(iunit, '(A)', iostat=ierr) nextline | ||
| if (ierr /= 0) exit GETMORE | ||
| if (nextline == 'NEXT') exit GETMORE | ||
|
|
||
| call get_args_from_string(nextline, nargs, args) | ||
| testnum = 'test 3' | ||
| call resetvals() | ||
| nextline = ' one two three' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| print *, 'input line: "'//trim(nextline)//'"' | ||
| print *, 'got ', nargs, ' arguments from the input line' | ||
| do i=1, nargs | ||
| print *, 'arg ', i, 'is: ', '"'//trim(args(i))//'"' | ||
| enddo | ||
| call ok((nargs == 3), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'one'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == 'two'), trim(testnum)//', arg 2') | ||
| call ok((args(3) == 'three'), trim(testnum)//', arg 3') | ||
| call ok((args(4) == ''), trim(testnum)//', arg 4') | ||
|
|
||
| enddo GETMORE | ||
|
|
||
| print *, 'enter lines with name=value separated by blanks.' | ||
| print *, 'enter control-D to end' | ||
| testnum = 'test 4' | ||
| call resetvals() | ||
| nextline = 'one two th/ree' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| !rewind(iunit) | ||
| GETMORE2 : do | ||
| read(iunit, '(A)', iostat=ierr) nextline | ||
| if (ierr /= 0) exit GETMORE2 | ||
| if (nextline == 'NEXT') exit GETMORE2 | ||
| call ok((nargs == 3), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'one'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == 'two'), trim(testnum)//', arg 2') | ||
| call ok((args(3) == 'th/ree'), trim(testnum)//', arg 3') | ||
| call ok((args(4) == ''), trim(testnum)//', arg 4') | ||
|
|
||
| call get_name_val_pairs_from_string(nextline, nargs, names, vals, continue_line) | ||
|
|
||
| print *, 'input line: "'//trim(nextline)//'"' | ||
| print *, 'got ', nargs, ' arguments from the input line' | ||
| do i=1, nargs | ||
| print *, 'name ', i, 'is: ', '"'//trim(names(i))//'"' | ||
| print *, 'value ', i, 'is: ', '"'//trim(vals(i))//'"' | ||
| enddo | ||
| print *, 'continue line = ', continue_line | ||
| testnum = 'test 5' | ||
| call resetvals() | ||
| nextline = '"quoted string"' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 1), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'quoted string'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == ''), trim(testnum)//', arg 2') | ||
|
|
||
|
|
||
| testnum = 'test 6' | ||
| call resetvals() | ||
| nextline = ' "quoted string" "second string with blanks" ' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 2), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'quoted string'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == 'second string with blanks'), trim(testnum)//', arg 2') | ||
| call ok((args(3) == ''), trim(testnum)//', arg 3') | ||
|
|
||
|
|
||
| testnum = 'test 7' | ||
| call resetvals() | ||
| nextline = '"quoted" "string"' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 2), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'quoted'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == 'string'), trim(testnum)//', arg 2') | ||
| call ok((args(3) == ''), trim(testnum)//', arg 3') | ||
|
|
||
|
|
||
| testnum = 'test 8' | ||
| call resetvals() | ||
| nextline = 'string'//BACKSLASH//'abc' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 1), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'stringabc'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == ''), trim(testnum)//', arg 2') | ||
|
|
||
|
|
||
| testnum = 'test 9' | ||
| call resetvals() | ||
| nextline = 'directory'//BACKSLASH//BACKSLASH//'abc' | ||
| call get_args_from_string(nextline, nargs, args) | ||
|
|
||
| call ok((nargs == 1), trim(testnum)//', nargs') | ||
| call ok((args(1) == 'directory'//BACKSLASH//'abc'), trim(testnum)//', arg 1') | ||
| call ok((args(2) == ''), trim(testnum)//', arg 2') | ||
|
|
||
|
|
||
| ! start of name/value pair tests | ||
|
|
||
| testnum = 'test 10' | ||
| call resetvals() | ||
| nextline = 'a=1 b=2 c=3' | ||
| call get_name_val_pairs_from_string(nextline, nargs, names, vals, continue_line) | ||
|
|
||
| call ok((nargs == 3), trim(testnum)//', nargs') | ||
| call ok((names(1) == 'a'), trim(testnum)//', name 1') | ||
| call ok((vals(1) == '1'), trim(testnum)//', val 1') | ||
| call ok((names(2) == 'b'), trim(testnum)//', name 2') | ||
| call ok((vals(2) == '2'), trim(testnum)//', val 2') | ||
| call ok((names(3) == 'c'), trim(testnum)//', name 3') | ||
| call ok((vals(3) == '3'), trim(testnum)//', val 3') | ||
| call ok((names(4) == ''), trim(testnum)//', name 4') | ||
| call ok((vals(4) == ''), trim(testnum)//', val 4') | ||
| call ok((.not. continue_line), trim(testnum)//', no continue_line') | ||
|
|
||
|
|
||
| testnum = 'test 11' | ||
| call resetvals() | ||
| nextline = 'a = 1.0 b = 2.0 c=3.0 &' | ||
| call get_name_val_pairs_from_string(nextline, nargs, names, vals, continue_line) | ||
|
|
||
| call ok((nargs == 3), trim(testnum)//', nargs') | ||
| call ok((names(1) == 'a'), trim(testnum)//', name 1') | ||
| call ok((vals(1) == '1.0'), trim(testnum)//', val 1') | ||
| call ok((names(2) == 'b'), trim(testnum)//', name 2') | ||
| call ok((vals(2) == '2.0'), trim(testnum)//', val 2') | ||
| call ok((names(3) == 'c'), trim(testnum)//', name 3') | ||
| call ok((vals(3) == '3.0'), trim(testnum)//', val 3') | ||
| call ok((names(4) == ''), trim(testnum)//', name 4') | ||
| call ok((vals(4) == ''), trim(testnum)//', val 4') | ||
| call ok(continue_line, trim(testnum)//', has continue_line') | ||
|
|
||
| enddo GETMORE2 | ||
|
|
||
| ! finalize parse_args_test | ||
| call error_handler(E_MSG,'parse_args_test','Finished successfully.',source,revision,revdate) | ||
| call finalize_utilities() | ||
|
|
||
| ! end of main code | ||
|
|
||
| !---------------------------------------------------------------------- | ||
|
|
||
| contains | ||
|
|
||
| subroutine resetvals() | ||
hkershaw-brown marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| integer :: i | ||
|
|
||
| nargs = -888 | ||
| do i=1, MAXVALS | ||
| args(i) = '' | ||
| names(i) = '' | ||
| vals(i) = '' | ||
| enddo | ||
|
|
||
| end subroutine resetvals | ||
|
|
||
|
|
||
| end program | ||
|
|
||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.