Remove gmx::File (except for File::exists())
[alexxy/gromacs.git] / src / gromacs / commandline / tests / pargs.cpp
index 55dc8b0c36cc163117f6c3f5e6f7b0641e6bacfa..53ea895be10a4677c24204753d5ce2837f869932 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * 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.
@@ -51,9 +51,9 @@
 #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"
@@ -108,7 +108,7 @@ class ParseCommonArgsTest : public ::testing::Test
                                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);
@@ -439,6 +439,27 @@ TEST_F(ParseCommonArgsTest, HandlesNonExistentOptionalInputFiles)
     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[] = {