diff --git a/Makefile b/Makefile
index 2dae10a6b4a6b9499a2d5f42cdfe3751f0e01ccb..fcb118746f971b9efe0aaf4509420195dc3efb1c 100644
--- a/Makefile
+++ b/Makefile
@@ -461,6 +461,7 @@ $(XTESTNAMEPREFIX)scandir_ino32.o: $(XTESTNAMEPREFIX)scandir.c
 # The nonstandard realpath tests include the realpath source
 $(TESTNAMEPREFIX)realpath_nonext.o: $(TESTNAMEPREFIX)realpath.c
 $(TESTNAMEPREFIX)realpath_nonposix.o: $(TESTNAMEPREFIX)realpath.c
+$(TESTNAMEPREFIX)realpath_compat.o: $(TESTNAMEPREFIX)realpath.c
 
 # Provide a target for all "darwin_c" tests
 $(XTESTRUNPREFIX)darwin_c_all: $(DARWINRUNS)
diff --git a/test/test_realpath.c b/test/test_realpath.c
index 8fcffd209f5c52d5b65df5e6322263403a0fafe6..ec890dcd233a3526101374b83c3738f28bd2c9ea 100644
--- a/test/test_realpath.c
+++ b/test/test_realpath.c
@@ -44,14 +44,25 @@ typedef struct { strfunc_t realpath; } rpf_t;
 
 #include <sys/param.h>
 
+/*
+ * Allow testing the legacy compatibility entry.
+ * We use a simple argless macro and disable the fancier tests.
+ */
+#ifdef TEST_MACPORTS_LEGACY_REALPATH
+#define realpath macports_legacy_realpath
+extern char *realpath(const char * __restrict, char * __restrict);
+#endif
+
 int
 main(int argc, char *argv[])
 {
   int verbose = 0;
   const char *p, *q;
+#ifndef TEST_MACPORTS_LEGACY_REALPATH
   strfunc_t f;
   rpf_t rpf = { realpath };
   rpv_t rpv;
+#endif /* !TEST_MACPORTS_LEGACY_REALPATH */
   char buf[PATH_MAX], cwd[MAXPATHLEN];
 
   if (argc > 1 && !strcmp(argv[1], "-v")) verbose = 1;
@@ -74,6 +85,7 @@ main(int argc, char *argv[])
   if (verbose) printf("realpath(path, NULL) supported.\n");
   free((void*)q);
 
+#ifndef TEST_MACPORTS_LEGACY_REALPATH
   /* Test with name (reference) only */
   f = realpath;
   q = f(".", NULL);
@@ -95,6 +107,7 @@ main(int argc, char *argv[])
   assert (!strcmp(rpv.realpath, p) && "rpf.realpath(path, NULL) miscompared");
   if (verbose) printf("rpv.realpath = rpf.realpath(path, NULL) supported.\n");
   free((void*)rpv.realpath);
+#endif /* !TEST_MACPORTS_LEGACY_REALPATH */
 
   printf("%s succeeded.\n", basename(argv[0]));
   return 0;
diff --git a/test/test_realpath_compat.c b/test/test_realpath_compat.c
new file mode 100644
index 0000000000000000000000000000000000000000..815875899fd3c928c329681e2086d349f5d11239
--- /dev/null
+++ b/test/test_realpath_compat.c
@@ -0,0 +1,25 @@
+/*
+ * Version of test_realpath for compatibility entry.
+ */
+
+/*
+ * This tests the macports_legacy_realpath() compatibility entry.
+ *
+ * For OS versions that never used the wrapper, this entire test is a dummy.
+ * Because of that condition, this test is an exception to the rule that tests
+ * shouldn't check the feature flags.
+ */
+
+/* MP support header */
+#include "MacportsLegacySupport.h"
+#if __MPLS_LIB_SUPPORT_REALPATH_WRAP__
+
+#define TEST_MACPORTS_LEGACY_REALPATH
+
+#include "test_realpath.c"
+
+#else /* !__MPLS_LIB_SUPPORT_REALPATH_WRAP__ */
+
+int main(){ return 0; }
+
+#endif /* !__MPLS_LIB_SUPPORT_REALPATH_WRAP__ */