mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-05-01 13:13:53 +00:00
Adding ofstream method
This commit is contained in:
parent
77071fdb95
commit
1d39e9f092
@ -56,6 +56,7 @@ TEST(AppHelper, TempfileCreated) {
|
||||
bool ok = static_cast<bool>(std::ofstream(myfile.c_str()).put('a')); // create file
|
||||
EXPECT_TRUE(ok);
|
||||
EXPECT_TRUE(CLI::ExistingFile(name));
|
||||
EXPECT_THROW({TempFile otherfile(name);}, std::runtime_error);
|
||||
}
|
||||
EXPECT_FALSE(CLI::ExistingFile(name));
|
||||
}
|
||||
@ -70,6 +71,23 @@ TEST(AppHelper, TempfileNotCreated) {
|
||||
EXPECT_FALSE(CLI::ExistingFile(name));
|
||||
}
|
||||
|
||||
TEST(AppHelper, Ofstream) {
|
||||
|
||||
std::string name = "TestFileNotUsed.txt";
|
||||
{
|
||||
TempFile myfile(name);
|
||||
|
||||
{
|
||||
std::ofstream out = myfile.ofstream();
|
||||
out << "this is output" << std::endl;
|
||||
}
|
||||
|
||||
EXPECT_TRUE(CLI::ExistingFile(myfile));
|
||||
}
|
||||
EXPECT_FALSE(CLI::ExistingFile(name));
|
||||
|
||||
}
|
||||
|
||||
TEST(Split, StringList) {
|
||||
|
||||
std::vector<std::string> results {"a", "long", "--lone", "-q"};
|
||||
|
@ -39,6 +39,9 @@ public:
|
||||
std::remove(_name.c_str()); // Doesn't matter if returns 0 or not
|
||||
}
|
||||
|
||||
/// Returns by move in C++11
|
||||
std::ofstream ofstream() const {return std::ofstream(_name);}
|
||||
|
||||
operator const std::string& () const {return _name;}
|
||||
const char * c_str() const {return _name.c_str();}
|
||||
const char* c_str() const {return _name.c_str();}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user