summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-05-17 01:02:36 +0300
committerAndrei Karas <akaras@inbox.ru>2012-05-17 01:38:56 +0300
commit61c92f38a7b9a5b30149bf5ae0cc106abc0482dc (patch)
treec2defab6c6152757ef99013ea226301834a73841
parentddf7d9970244385eaba19f60c76deeab3f507c29 (diff)
downloadmanaplus-61c92f38a7b9a5b30149bf5ae0cc106abc0482dc.tar.gz
manaplus-61c92f38a7b9a5b30149bf5ae0cc106abc0482dc.tar.bz2
manaplus-61c92f38a7b9a5b30149bf5ae0cc106abc0482dc.tar.xz
manaplus-61c92f38a7b9a5b30149bf5ae0cc106abc0482dc.zip
Fix invoking tests.
Remove shell script for tests.
-rwxr-xr-xmanaplustest5
-rw-r--r--manaplustest.desktop2
-rw-r--r--src/test/testmain.cpp3
-rw-r--r--src/utils/paths.cpp50
-rw-r--r--src/utils/paths.h2
5 files changed, 55 insertions, 7 deletions
diff --git a/manaplustest b/manaplustest
deleted file mode 100755
index 12bdc2b8a..000000000
--- a/manaplustest
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-
-cd $(dirname $(whereis -b manaplus|cut -d " " -f 2))
-
-manaplus --tests
diff --git a/manaplustest.desktop b/manaplustest.desktop
index 005be4ea9..11947fa03 100644
--- a/manaplustest.desktop
+++ b/manaplustest.desktop
@@ -3,7 +3,7 @@
Version=1.0
Name=ManaPlus (Tests)
Comment=Run tests for ManaPlus
-Exec=manaplustest
+Exec=manaplus --tests
StartupNotify=false
Terminal=false
Type=Application
diff --git a/src/test/testmain.cpp b/src/test/testmain.cpp
index f5bdc5711..eb24a2c75 100644
--- a/src/test/testmain.cpp
+++ b/src/test/testmain.cpp
@@ -29,6 +29,7 @@
#include "utils/gettext.h"
#include "utils/mkdir.h"
#include "utils/stringutils.h"
+#include "utils/paths.h"
#include "utils/process.h"
#include <iostream>
@@ -43,7 +44,7 @@ TestMain::TestMain()
#ifdef WIN32
fileName = "manaplus.exe";
#else
- fileName = selfName;
+ fileName = getSelfName();
#endif
log = new Logger;
diff --git a/src/utils/paths.cpp b/src/utils/paths.cpp
index 04f553ca9..306955cb3 100644
--- a/src/utils/paths.cpp
+++ b/src/utils/paths.cpp
@@ -75,3 +75,53 @@ std::string &fixDirSeparators(std::string &str)
return replaceAll(str, "/", "\\");
}
+
+std::string removeLast(std::string str)
+{
+ size_t pos2 = str.rfind("/");
+ size_t pos3 = str.rfind("\\");
+ if (pos3 != std::string::npos)
+ {
+ if (pos2 == std::string::npos || pos3 > pos2)
+ pos2 = pos3;
+ }
+ if (pos2 == std::string::npos)
+ pos2 = -1;
+ if (pos2 >= 0)
+ return str.substr(0, pos2);
+ else
+ return str;
+}
+
+#ifdef WIN32
+std::string getSelfName()
+{
+ // GetModuleFileName(nullptr)
+ return "";
+}
+
+#elif defined(__APPLE__)
+std::string getSelfName()
+{
+ return "";
+}
+
+#elif defined __linux__ || defined __linux
+#include <unistd.h>
+
+std::string getSelfName()
+{
+ char buf[257];
+ int sz = readlink("/proc/self/exe", buf, 256);
+ if (sz > 0 && sz < 256)
+ {
+ buf[sz] = 0;
+ return buf;
+ }
+ else
+ {
+ return "";
+ }
+}
+
+#endif
diff --git a/src/utils/paths.h b/src/utils/paths.h
index b89671adc..18fa4629e 100644
--- a/src/utils/paths.h
+++ b/src/utils/paths.h
@@ -31,4 +31,6 @@ bool checkPath(std::string path);
std::string &fixDirSeparators(std::string &str);
+std::string getSelfName();
+
#endif // UTILS_PATHS_H