/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
* \author Teemu Murtola <teemu.murtola@gmail.com>
* \ingroup module_commandline
*/
+#include "gmxpre.h"
+
#include "gromacs/commandline/pargs.h"
#include <string>
#include <gtest/gtest.h>
#include "gromacs/utility/arrayref.h"
-#include "gromacs/utility/file.h"
#include "gromacs/utility/path.h"
#include "gromacs/utility/stringutil.h"
+#include "gromacs/utility/textwriter.h"
#include "testutils/cmdlinetest.h"
#include "testutils/testasserts.h"
FileArgumentType type)
{
std::string filename(tempFiles_.getTemporaryFilePath(extension));
- gmx::File::writeFileFromString(filename, "Dummy file");
+ gmx::TextWriter::writeFileFromString(filename, "Dummy file");
if (name != NULL)
{
args_.append(name);
done_filenms(nfile(), fnm);
}
+TEST_F(ParseCommonArgsTest, ParseFileArgsWithCustomDefaultExtension)
+{
+ t_filenm fnm[] = {
+ { efTRX, "-o1", "conf1.gro", ffWRITE },
+ { efTRX, "-o2", "conf2.pdb", ffWRITE },
+ { efTRX, "-o3", "conf3.gro", ffWRITE }
+ };
+ const char *const cmdline[] = {
+ "test", "-o2", "-o3", "test"
+ };
+ parseFromArray(cmdline, PCA_CAN_SET_DEFFNM, fnm, gmx::EmptyArrayRef());
+ EXPECT_STREQ("conf1.gro", opt2fn("-o1", nfile(), fnm));
+ EXPECT_STREQ("conf2.pdb", opt2fn("-o2", nfile(), fnm));
+ EXPECT_STREQ("test.gro", opt2fn("-o3", nfile(), fnm));
+ done_filenms(nfile(), fnm);
+}
+
/********************************************************************
* Tests for file name options (input files, dependent on file system contents)
*/
done_filenms(nfile(), fnm);
}
+TEST_F(ParseCommonArgsTest, AcceptsNonExistentInputFilesIfSpecified)
+{
+ t_filenm fnm[] = {
+ { efCPT, "-c", "file1", ffOPTRD | ffALLOW_MISSING },
+ { efCPT, "-c2", "file2", ffOPTRD | ffALLOW_MISSING },
+ { efCPT, "-c3", "file3", ffOPTRD | ffALLOW_MISSING },
+ { efCPT, "-c4", "file4", ffOPTRD | ffALLOW_MISSING },
+ { efTRX, "-f", "trj", ffOPTRD | ffALLOW_MISSING }
+ };
+ const char *const cmdline[] = {
+ "test", "-c2", "-c3", "nonexistent", "-c4", "nonexistent.cpt", "-f", "nonexistent"
+ };
+ parseFromArray(cmdline, 0, fnm, gmx::EmptyArrayRef());
+ EXPECT_STREQ("file1.cpt", opt2fn("-c", nfile(), fnm));
+ EXPECT_STREQ("file2.cpt", opt2fn("-c2", nfile(), fnm));
+ EXPECT_STREQ("nonexistent.cpt", opt2fn("-c3", nfile(), fnm));
+ EXPECT_STREQ("nonexistent.cpt", opt2fn("-c4", nfile(), fnm));
+ EXPECT_STREQ("nonexistent.xtc", opt2fn("-f", nfile(), fnm));
+ done_filenms(nfile(), fnm);
+}
+
TEST_F(ParseCommonArgsTest, HandlesCompressedFiles)
{
t_filenm fnm[] = {
{
t_filenm fnm[] = {
{ efTRX, "-f1", NULL, ffREAD },
- { efTPX, "-f2", "foo", ffREAD },
+ { efSTO, "-f2", "foo", ffREAD },
{ efTRX, "-f3", NULL, ffREAD },
{ efSTX, "-f4", NULL, ffREAD }
};
args_.append("test");
std::string expected1 = addFileArg("-f1", "1.trr", efNoExtension);
- std::string expected2 = addFileArg("-f2", ".tpa", efEmptyValue);
+ std::string expected2 = addFileArg("-f2", ".pdb", efEmptyValue);
std::string expected3 = addFileArg("-f3", ".trr", efEmptyValue);
std::string expected4 = addFileArg(NULL, ".pdb", efEmptyValue);
std::string deffnm = gmx::Path::stripExtension(expected3);