From 937c17f3b88a775857cec269f8d3c9faf9e94227 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 7 Aug 2024 10:27:48 -0400 Subject: [PATCH] add tests for geturl command --- unittest/commands/test_simple_commands.cpp | 51 ++++++++++++++++++++-- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/unittest/commands/test_simple_commands.cpp b/unittest/commands/test_simple_commands.cpp index 79ea1c71ce..d3fef447ac 100644 --- a/unittest/commands/test_simple_commands.cpp +++ b/unittest/commands/test_simple_commands.cpp @@ -19,6 +19,7 @@ #include "info.h" #include "input.h" #include "output.h" +#include "platform.h" #include "update.h" #include "utils.h" #include "variable.h" @@ -214,9 +215,9 @@ TEST_F(SimpleCommandsTest, Quit) TEST_FAILURE(".*ERROR: Expected integer .*", command("quit xxx");); // the following tests must be skipped with OpenMPI or MPICH 4.1 and later due to using threads - if (platform::mpi_vendor() == "Open MPI") GTEST_SKIP(); + if (platform::mpi_vendor() == "Open MPI") GTEST_SKIP() << "OpenMPI"; #if defined(MPICH_NUMVERSION) - if (MPICH_NUMVERSION >= 40100000) GTEST_SKIP(); + if (MPICH_NUMVERSION >= 40100000) GTEST_SKIP() << "MPICH with threads"; #endif ASSERT_EXIT(command("quit"), ExitedWithCode(0), ""); ASSERT_EXIT(command("quit 9"), ExitedWithCode(9), ""); @@ -412,7 +413,7 @@ TEST_F(SimpleCommandsTest, Plugin) { const char *bindir = getenv("LAMMPS_PLUGIN_BIN_DIR"); const char *config = getenv("CMAKE_CONFIG_TYPE"); - if (!bindir) GTEST_SKIP(); + if (!bindir) GTEST_SKIP() << "LAMMPS_PLUGIN_BIN_DIR not set"; std::string loadfmt = platform::path_join("plugin load ", bindir); if (config) loadfmt = platform::path_join(loadfmt, config); loadfmt = platform::path_join(loadfmt, "{}plugin.so"); @@ -556,6 +557,50 @@ TEST_F(SimpleCommandsTest, CiteMe) // no new citation. no CITE-CITE-CITE- lines ASSERT_THAT(text, Not(ContainsRegex(".*CITE-CITE-CITE-CITE.*"))); } + +TEST_F(SimpleCommandsTest, Geturl) +{ + if (!LAMMPS::is_installed_pkg("EXTRA-COMMAND")) GTEST_SKIP(); + platform::unlink("index.html"); + platform::unlink("myindex.html"); + if (Info::has_curl_support()) { + BEGIN_CAPTURE_OUTPUT(); + command("geturl https://www.lammps.org/index.html"); + command("geturl https://www.lammps.org/index.html output myindex.html"); + END_CAPTURE_OUTPUT(); + EXPECT_TRUE(platform::file_is_readable("index.html")); + EXPECT_TRUE(platform::file_is_readable("myindex.html")); + FILE *fp = fopen("index.html", "wb"); + fputs("just testing\n", fp); + fclose(fp); + BEGIN_CAPTURE_OUTPUT(); + command("geturl https://www.lammps.org/index.html overwrite no"); + END_CAPTURE_OUTPUT(); + char checkme[20]; + fp = fopen("index.html", "rb"); + fgets(checkme, 19, fp); + fclose(fp); + EXPECT_EQ(strcmp(checkme, "just testing\n"), 0); + BEGIN_CAPTURE_OUTPUT(); + command("geturl https://www.lammps.org/index.html overwrite yes"); + END_CAPTURE_OUTPUT(); + fp = fopen("index.html", "rb"); + fgets(checkme, 19, fp); + fclose(fp); + EXPECT_NE(strcmp(checkme, "just testing\n"), 0); + TEST_FAILURE(".*ERROR: Illegal geturl command: missing argument.*", command("geturl ");); + TEST_FAILURE(".*ERROR: URL 'dummy' is not a supported URL.*", command("geturl dummy");); + TEST_FAILURE(".*ERROR on proc 0: Download of xxx.txt failed with: " + "HTTP response code said error 404.*", + command("geturl https://www.lammps.org/xxx.txt");); + } else { + TEST_FAILURE(".*ERROR: LAMMPS has not been compiled with libcurl support*", + command("geturl https:://www.lammps.org/index.html");); + } + platform::unlink("index.html"); + platform::unlink("myindex.html"); +} + } // namespace LAMMPS_NS int main(int argc, char **argv)