From c470d92366d7c3c239a689f0a10d6d0d9daafbff Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 18 May 2020 11:55:54 +0200 Subject: Allow prefix to be a complete filename for GetTempFile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Our testcases had their own implementation of GetTempFile with the feature of a temporary file with a choosen suffix. Merging this into GetTempFile lets us drop this duplicate and hence test more our code rather than testing our helpers for test implementation. And then hashsums_test had another implementation… and extracttar wasn't even trying to use a real tempfile… one GetTempFile to rule them all! That also ensures that these tempfiles are created in a temporary directory rather than the current directory which is a nice touch and tries a little harder to clean up those tempfiles. --- test/libapt/configuration_test.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'test/libapt/configuration_test.cc') diff --git a/test/libapt/configuration_test.cc b/test/libapt/configuration_test.cc index 8d6c404b3..4d297a9f2 100644 --- a/test/libapt/configuration_test.cc +++ b/test/libapt/configuration_test.cc @@ -198,9 +198,8 @@ TEST(ConfigurationTest,Merge) TEST(ConfigurationTest, Parsing) { Configuration Cnf; - std::string tempfile; - FileFd fd; - createTemporaryFile("doublesignedfile", fd, &tempfile, R"apt( + { + auto const file = createTemporaryFile("doublesignedfile", R"apt( SimpleOption "true"; /* SimpleOption "false"; */ Answer::Simple "42"; @@ -213,9 +212,8 @@ List::Option2 { "Multi"; }; Trailing "true"; /* Commented::Out "true"; */ )apt"); - EXPECT_TRUE(ReadConfigFile(Cnf, tempfile)); - if (tempfile.empty() == false) - unlink(tempfile.c_str()); + EXPECT_TRUE(ReadConfigFile(Cnf, file.Name())); + } EXPECT_TRUE(Cnf.FindB("SimpleOption")); EXPECT_EQ(42, Cnf.FindI("Answer::Simple")); EXPECT_TRUE(Cnf.Exists("List::Option")); -- cgit v1.2.3-70-g09d2