Commit 2264d7c5 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.16

parent f1556ec3
Package: getopt
Type: Package
Title: C-like getopt behavior.
Version: 1.15
Version: 1.16
Date: 2010-04-28
Author: Allen Day <allenday@ucla.edu>
Maintainer: Allen Day <allenday@ucla.edu>
Maintainer: Trevor Davis <trevor.l.davis@stanford.edu>
Description: Use this with Rscript to write ``#!'' shebang scripts that
accept short and long flags/options.
License: GPL (>= 2)
Packaged: 2010-04-28 08:46:22 UTC; root
Suggests: testthat
Repository: CRAN
Date/Publication: 2010-04-28 09:19:33
Repository/R-Forge/Project: optparse
Repository/R-Forge/Revision: 79
Date/Publication: 2011-05-02 09:39:37
Packaged: 2011-05-01 20:52:56 UTC; rforge
......@@ -142,7 +142,7 @@ getopt = function (spec=NULL,opt=commandArgs(TRUE),command=strsplit(commandArgs(
kv = strsplit(optstring, '=')[[1]];
if ( !is.na(kv[2]) ) {
this.flag = kv[1];
this.argument = kv[2];
this.argument = paste(kv[-1], collapse="=");
} else {
this.flag = optstring;
}
......
......@@ -200,7 +200,7 @@ spec = c(
);
opt = getopt(spec, c('--date','20080421','--market','YM','--getdata'));
opt = getopt(spec, c('--date','20080421','--getdata','--market','YM'));
opt = getopt(spec, c('--date','20080421','--getdata','--market','YM'),usage=TRUE,debug=TRUE);
opt = getopt(spec, c('--date','20080421','--getdata','--market','YM'),debug=TRUE);
print(getopt(spec, c('--date','20080421','--getdata','--market','YM'),usage=TRUE));
}
\keyword{ data }% at least one, from doc/KEYWORDS
library("testthat")
library("getopt")
context("Testing getopt")
test_that("getopt works as expected", {
spec = matrix(c(
'verbose', 'v', 2, "integer",
'help' , 'h', 0, "logical",
'dummy1' , 'd', 0, "logical",
'dummy2' , 'e', 2, "logical",
'count' , 'c', 1, "integer",
'mean' , 'm', 1, "double",
'sd' , 's', 1, "double",
'output' , 'O', 1, "character"
), ncol=4, byrow=TRUE);
sort_list <- function(unsorted_list) {
for(ii in seq(along=unsorted_list)) {
if(is.list(unsorted_list[[ii]])) {
unsorted_list[[ii]] <- unsorted_list[[ii]][sort(names(unsorted_list[[ii]]))]
}
}
unsorted_list[sort(names(unsorted_list))]
}
expect_equal(sort_list(getopt(spec, c('-c', '-1', '-m', '-1.2'))),
sort_list(list(ARGS=character(0), count=-1, mean=-1.2)));
expect_equal(sort_list(getopt(spec, c('-v', '-m', '3'))),
sort_list(list(ARGS=character(0), verbose=1, mean=3)));
expect_equal(sort_list(getopt(spec, c('-m', '3', '-v'))),
sort_list(list(ARGS=character(0), mean=3, verbose=1)));
expect_equal(sort_list(getopt(spec, c('-m', '3', '-v', '2', '-v'))),
sort_list(list(ARGS=character(0), mean=3, verbose=1)));
expect_equal(sort_list(getopt(spec, c('-O', '-', '-m', '3'))),
sort_list(list(ARGS=character(0), output="-", mean=3)));
expect_equal(sort_list(getopt(spec, c('-O', '-', '-m', '3'))),
sort_list(getopt(spec, c('-m', '3', '-O', '-'))));
expect_equal(sort_list(getopt(spec, c('-de'))),
sort_list(getopt(spec, c('-ed'))));
expect_equal(sort_list(getopt(spec, c('-de'))),
sort_list(list(ARGS=character(0), dummy1=TRUE, dummy2=TRUE)));
expect_equal(sort_list(getopt(spec, c('-de', '1'))),
sort_list(list(ARGS=character(0), dummy1=TRUE, dummy2=NA)));
expect_equal(sort_list(getopt(spec, c('--verbose'))),
sort_list(list(ARGS=character(0), verbose=1)));
expect_equal(sort_list(getopt(spec, c('--verbose', '--help'))),
sort_list(list(ARGS=character(0), verbose=1, help=TRUE)));
expect_equal(sort_list(getopt(spec, c('--verbose', '--mean', '5'))),
sort_list(list(ARGS=character(0), verbose=1, mean=5)));
expect_equal(sort_list(getopt(spec, c('--mean=5'))),
sort_list(list(ARGS=character(0), mean=5)));
expect_equal(sort_list(getopt(spec, c('--verbose', '--mean=5', '--sd', '5'))),
sort_list(list(ARGS=character(0), verbose=1, mean=5, sd=5)));
expect_equal(sort_list(getopt(spec, c('--verbose', '--mean=5', '--sd', '5'))),
sort_list(getopt(spec, c('--mean=5', '--sd', '5', '--verbose'))));
spec = c(
'date' , 'd', 1, "character",
'help' , 'h', 0, "logical",
'getdata' , 'g', 0, "logical",
'market' , 'm', 1, "character",
'threshold', 't', 1, "double"
);
# should give warning is spec is not matrix
expect_that(getopt(spec, c('--date','20080421','--market','YM','--getdata')), gives_warning());
expect_equal(sort_list(getopt(spec, c('--date','20080421','--market','YM','--getdata'))),
sort_list(list(ARGS=character(0), date='20080421', market='YM', getdata=TRUE)))
expect_equal(sort_list(getopt(spec, c('--date','20080421','--market','YM','--getdata'))),
sort_list(getopt(spec, c('--date','20080421','--getdata','--market','YM'))));
expect_that(getopt(spec, c('--date','20080421','--getdata','--market','YM'),debug=TRUE),
prints_text("processing "));
expect_that(print(getopt(spec, c('--date','20080421','--getdata','--market','YM'),usage=TRUE)),
prints_text("Usage: "));
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment