瀏覽代碼

Unit test: Add diagnostic message, if CGI test executable does not exist.

It would also be possible to build the test executable from a CMakeFile,
but we create it when preparing the test environment, e.g., by calling
gcc in a .travis.yml file. This way we test the build/test environment
before using the actual CMakefile or any source file.
Rarely, but nevertheless every now and then, something goes wrong when
preparing the test environment. This kind of errors are detected before
starting the CMake-build when executing .travis.yml or appveyor.yml.

If someone uses CMake on a local machine without executing the build
step for the CGI test executable manually, the test will fail.

This commit adds a diagnostic message, telling the user to create the
cgi_test.cgi executable before starting the test.
This was a remaining request from #402.

In case this kind of check is no longer required, one might still add
the build for cgi_test.cgi to the CMakeFile of the unit test.
bel2125 8 年之前
父節點
當前提交
f903881963
共有 1 個文件被更改,包括 19 次插入0 次删除
  1. 19 0
      test/public_server.c

+ 19 - 0
test/public_server.c

@@ -1076,6 +1076,7 @@ START_TEST(test_request_handlers)
 	const char *cgi_script_content;
 	const char *expected_cgi_result;
 	int opt_idx = 0;
+	struct stat st;
 
 #if !defined(NO_SSL)
 	const char *ssl_cert = locate_ssl_cert();
@@ -1397,6 +1398,24 @@ START_TEST(test_request_handlers)
 	mg_close_connection(client_conn);
 
 
+/* Check if CGI test executable exists */
+#if defined(_WIN32)
+        sprintf(cmd_buf, %s\\cgi_test.cgi", locate_test_exes());
+#else
+	sprintf(cmd_buf, "%s/cgi_test.cgi", locate_test_exes());
+#endif
+        memset(&st, 0, sizeof(st));
+        if (stat(buf, &st) != 0) {
+		fprintf(stderr, "\nFile %s not found\n", cmd_buf);
+		fprintf(stderr, "This file needs to be compiled manually before "
+		                "starting the test\n", );
+		fprintf(stderr,
+		        "e.g. by gcc test/cgi_test.c -o output/cgi_test.cgi\n\n", );
+		ck_abort_msg("Mandatory file %s must be built before starting the test",
+		             cmd_buf);
+        }
+
+
 /* Test with CGI test executable */
 #if defined(_WIN32)
 	sprintf(cmd_buf, "copy %s\\cgi_test.cgi cgi_test.exe", locate_test_exes());