diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
deleted file mode 100644
index 0e0d90292..000000000
--- a/tests/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-project(runtest)
-
-cmake_minimum_required(VERSION 2.4.0)
-if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
-endif(COMMAND cmake_policy)
-
-#if (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
-# message(FATAL_ERROR "Clang is the only supported compiler.")
-#endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
-
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
-#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC")
-
-set(runtest_SRCS
- runtest.cpp
- termcolor.cpp
- pstream.cpp
- boostxml.cpp
- timer.cpp
-)
-
-add_executable(runtest ${runtest_SRCS})
-target_link_libraries(runtest sshcxx)
-
-add_subdirectory(libsshcxx)
-add_dependencies(runtest sshcxx)
-
-#install(TARGETS runtest DESTINATION "lib${SUFFIX}/darling")
-
diff --git a/tests/boostxml.cpp b/tests/boostxml.cpp
deleted file mode 100644
index 92a1c80d4..000000000
--- a/tests/boostxml.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#include "boostxml.h"
-
-boostxml::boostxml()
-{
- m_xml << "\n";
- m_xml << "\n";
- m_xml << "\t\n";
-}
-
-void boostxml::addOK(const std::string& path, int time)
-{
- m_xml << "\t\t\n";
- m_xml << "\t\t\t" << time << "\n";
- m_xml << "\t\t\n";
-}
-
-void boostxml::addFailure(const std::string& path, int time, const std::string& error)
-{
- m_xml << "\t\t\n";
- m_xml << "\t\t\t\n";
- m_xml << "\n";
- m_xml << "\t\t\t\n";
- m_xml << "\t\t\t" << time << "\n";
- m_xml << "\t\t\n";
-}
-
-std::string boostxml::str()
-{
- m_xml << "\t\n\n";
- return m_xml.str();
-}
-
-std::string boostxml::extractName(const std::string& path)
-{
- size_t pos = path.rfind('/');
- if (pos == std::string::npos)
- return path;
- else
- return path.substr(pos+1);
-}
-
diff --git a/tests/boostxml.h b/tests/boostxml.h
deleted file mode 100644
index ac3738711..000000000
--- a/tests/boostxml.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef BOOSTXML_H
-#define BOOSTXML_H
-#include
-#include
-
-class boostxml
-{
-public:
- boostxml();
- std::string str();
-
- void addOK(const std::string& path, int time);
- void addFailure(const std::string& path, int time, const std::string& error);
-private:
- static std::string extractName(const std::string& path);
-private:
- std::stringstream m_xml;
-};
-
-#endif
-
diff --git a/tests/exceptions.h b/tests/exceptions.h
deleted file mode 100644
index e9a5e65a5..000000000
--- a/tests/exceptions.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef __EXCEPTIONS_H
-#define __EXCEPTIONS_H
-#include
-#include
-
-class compile_error : public std::runtime_error
-{
-public:
- compile_error(const std::string& err)
- : std::runtime_error(err)
- {
- }
-};
-
-class different_output_error : public std::exception
-{
-public:
- different_output_error(const std::string& remote, const std::string& local)
- : m_remote(remote), m_local(local)
- {
- }
-
- virtual const char* what() const throw() override
- {
- return "different_output_error";
- }
-
- const std::string& local() const { return m_local; }
- const std::string& remote() const { return m_remote; }
-private:
- std::string m_local, m_remote;
-};
-
-class nonzero_exit_error : public std::exception
-{
-public:
- nonzero_exit_error(bool remote, const std::string& output)
- : m_remote(remote), m_output(output)
- {
- std::stringstream ss;
- ss << "Non-zero exit status from ";
- if (m_remote)
- ss << "remotely";
- else
- ss << "locally";
- ss << " run binary";
- m_msg = ss.str();
- }
-
- bool remote() const { return m_remote; }
- const std::string& output() const { return m_output; }
-
- virtual const char* what() const throw() override
- {
- return m_msg.c_str();
- }
-private:
- bool m_remote;
- std::string m_output, m_msg;
-};
-
-#endif
-
-
diff --git a/tests/pstream.cpp b/tests/pstream.cpp
deleted file mode 100644
index 9d120e15f..000000000
--- a/tests/pstream.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-#include "pstream.h"
-#include
-
-
-pstream::pstream(FILE* pipe)
-: m_pipe(pipe)
-{
-}
-
-pstream::~pstream()
-{
- if (m_pipe)
- wait();
-}
-
-pstream* pstream::popen(const std::string& cmd)
-{
- FILE* pipe = ::popen(cmd.c_str(), "r");
- if (!pipe)
- return nullptr;
- return new pstream(pipe);
-}
-
-std::istream* pstream::in()
-{
- return new std::istream(this);
-}
-
-int pstream::wait()
-{
- int rv = pclose(m_pipe);
- m_pipe = nullptr;
- return rv;
-}
-
-std::streamsize pstream::xsgetn(char* s, std::streamsize n)
-{
- return fread(s, 1, n, m_pipe);
-}
diff --git a/tests/pstream.h b/tests/pstream.h
deleted file mode 100644
index b97304525..000000000
--- a/tests/pstream.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "libsshcxx/ssh_streambuf.h"
-#include
-#include
-#include
-
-class pstream : public ssh_streambuf
-{
-public:
- pstream(FILE* pipe);
- ~pstream();
-
- static pstream* popen(const std::string& cmd);
-
- std::istream* in();
- int wait();
-protected:
- virtual std::streamsize xsgetn(char* s, std::streamsize n) override;
-private:
- FILE* m_pipe;
-};
diff --git a/tests/runtest b/tests/runtest
deleted file mode 100755
index 45a37ebcc..000000000
--- a/tests/runtest
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/bash
-
-BUILDSERVER="osx"
-CPPFLAGS=""
-DYLD="dyld"
-
-set -e
-
-failure() {
- tput setaf 1
- tput bold
- echo "Test failure - the last command failed to execute"
- tput sgr0
-}
-
-runtest() {
- trap failure ERR
-
- source="$1"
- extension="${source##*.}"
- source_fn=$(echo "$source" | sed 's/\//_/g')
-
- cflags="$(grep '// CFLAGS' "$source" || true)"
- cflags="$CPPFLAGS -w $(echo "$cflags" | cut -b 12-)"
-
- case "$extension" in
- "cpp")
- darwin_tool="g++"
- native_tool="clang++"
- ;;
- "c")
- darwin_tool="gcc"
- native_tool="clang"
- ;;
- "m")
- darwin_tool="gcc"
- native_tool="clang"
- cflags_native="-l:libobjc.so.4 -lgnustep-base"
- cflags_darwin="-lobjc -framework foundation"
- ;;
- *)
- echo "Unsupported file type: $extension"
- exit 1
- esac
-
- tput bold
- echo "====="
- echo "Running test '$source'"
- echo "====="
- tput sgr0
-
- cflags="$(grep '// CFLAGS' "$source" || true)"
- cflags="$CPPFLAGS -w $(echo "$cflags" | cut -b 12-)"
-
- echo "Copying the source code to Darwin..."
- scp "$source" "$BUILDSERVER:/tmp/$$.$source_fn" >/dev/null
- echo "Building the source code for Darwin..."
- ssh "$BUILDSERVER" "$darwin_tool $cflags $cflags_darwin '/tmp/$$.$source_fn' -o '/tmp/$$.$source_fn.bin'"
- echo "Copying the binary over..."
- scp "$BUILDSERVER:/tmp/$$.$source_fn.bin" "/tmp" >/dev/null
- ssh "$BUILDSERVER" "rm -f /tmp/$$.$source_fn*"
-
- echo "Running Darwin binary locally..."
- out_darwin=$($DYLD "/tmp/$$.$source_fn.bin")
- rm -f "/tmp/$$.$source_fn.bin"
-
- echo "Compiling native..."
- $native_tool $cflags $cflags_native "$source" -o "/tmp/$$.$source_fn.bin"
- echo "Running native binary..."
- out_native=$("/tmp/$$.$source_fn.bin")
-
- if [ "$out_darwin" != "$out_native" ]; then
- tput setaf 1
- tput bold
- echo "*** ERROR: Outputs do not match!"
- tput sgr0
- echo "---"
- tput setaf 3
- echo "Darwin build:"
- tput sgr0
- echo "---"
- echo "$out_darwin"
- echo "---"
- tput setaf 3
- echo "Native build:"
- tput sgr0
- echo "---"
- echo "$out_native"
- exit 1
- fi
- rm -f "/tmp/$$.$source_fn.bin"
-
- tput setaf 2
- echo "Everything OK, outputs match"
- tput sgr0
-}
-
-if [[ "$0" == *runtest32 ]]; then
- CPPFLAGS="-m32"
- DYLD="dyld32"
- echo "32-bit mode"
-fi
-if [[ "$0" == *runtest64 ]]; then
- DYLD="dyld64"
- echo "64-bit mode"
-fi
-
-for test in "$@"; do
- runtest "$test"
-done
-
-tput bold
-tput setaf 2
-echo '====='
-echo 'ALL GOOD'
-echo '====='
-tput sgr0
-
diff --git a/tests/runtest.cpp b/tests/runtest.cpp
deleted file mode 100644
index 27b8685fc..000000000
--- a/tests/runtest.cpp
+++ /dev/null
@@ -1,362 +0,0 @@
-#include
-#include "libsshcxx/SSH.h"
-#include "libsshcxx/SFTP.h"
-#include "libsshcxx/SSHChannel.h"
-#include "termcolor.h"
-#include "pstream.h"
-#include "exceptions.h"
-#include "boostxml.h"
-#include "timer.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-const char* DYLD_COMMAND = "dyld";
-const char* OSX_HOST = "osx";
-std::unique_ptr g_ssh;
-std::unique_ptr g_sftp;
-std::unique_ptr g_shell;
-
-void bits(const char* progname);
-void runTest(const char* path);
-std::string uniqueName(const std::string& path);
-std::string cflags(const char* path);
-const char* compiler(const char* path);
-std::string stripext(std::string file);
-
-int main(int argc, char** argv)
-{
- if (argc < 2)
- {
- std::cerr << "Specify the tests to run\n";
- return 1;
- }
-
- bits(argv[0]);
- if (const char* cmd = getenv("DYLD"))
- DYLD_COMMAND = cmd;
-
- try
- {
- std::cout << "Opening SSH connection...\n";
- g_ssh.reset(new SSH);
- g_ssh->setHost(OSX_HOST);
- g_ssh->connect();
- g_ssh->login();
- g_shell.reset(g_ssh->newChannel());
- g_shell->openNonInteractive();
- g_shell->startShell();
- g_sftp.reset(g_ssh->sftpChannel());
-
- int failures = 0;
- int offset = 0;
- timer tm;
- std::ofstream xml;
- boostxml bxml;
-
- if (argc >= 2 && strncmp(argv[1], "--xml=", 6) == 0)
- {
- xml.open(argv[1] + 6, std::ofstream::out);
- offset++;
- }
-
- for (int i = offset+1; i < argc; i++)
- {
- time_t timeStart, timeEnd;
- try
- {
- termcolor::set(termcolor::WHITE, termcolor::BLACK, termcolor::BRIGHT);
- std::cout << "=======\n";
- std::cout << "Running test (" << i-offset << '/' << argc-1 << "): " << argv[i] << std::endl;
- std::cout << "=======\n";
- termcolor::reset();
-
- tm.start();
-
- runTest(argv[i]);
- bxml.addOK(argv[i], tm.stop());
-
- termcolor::set(termcolor::GREEN, termcolor::BLACK, termcolor::BRIGHT);
- std::cout << "*** Test OK!\n";
- termcolor::reset();
- }
- catch (const std::runtime_error& e)
- {
- termcolor::setBright(termcolor::RED);
- std::cerr << "*** Test failure!\n";
- termcolor::reset();
-
- std::cerr << e.what() << std::endl;
- bxml.addFailure(argv[i], tm.stop(), e.what());
-
- failures++;
- }
- catch (const different_output_error& e)
- {
- termcolor::setBright(termcolor::RED);
- std::cerr << "*** Test failure!\n";
- termcolor::reset();
-
- termcolor::setBright(termcolor::WHITE);
- std::cerr << "Remote output:\n";
- termcolor::reset();
- std::cerr << e.remote();
-
- termcolor::setBright(termcolor::WHITE);
- std::cerr << "Local output:\n";
- termcolor::reset();
- std::cerr << e.local();
-
- std::stringstream ss;
- ss << "Test outputs differ!\n\n";
- ss << "Remote output:\n";
- ss << e.remote() << "\n\n";
- ss << "Local output:\n";
- ss << e.local();
- bxml.addFailure(argv[i], tm.stop(), ss.str());
-
- failures++;
- }
- catch (const nonzero_exit_error& e)
- {
- termcolor::setBright(termcolor::RED);
- std::cerr << "*** Non-zero exit status!\n";
- termcolor::reset();
-
- termcolor::setBright(termcolor::WHITE);
- std::cerr << ((e.remote()) ? "remote" : "local" );
- std::cerr << " test output leading to the error:\n";
- termcolor::reset();
- std::cerr << e.output();
-
- std::stringstream ss;
- ss << "Non-zero exit status (" << ((e.remote() ? "remote" : "local")) << ")\n";
- ss << e.output();
-
- bxml.addFailure(argv[i], tm.stop(), ss.str());
-
- failures++;
- }
- }
-
- if (!failures)
- {
- termcolor::setBright(termcolor::GREEN);
- std::cout << "ALL OK!\n";
- }
- else
- {
- termcolor::setBright(termcolor::YELLOW);
- std::cerr << failures << " test failures\n";
- }
-
- termcolor::reset();
- xml << bxml.str();
- }
- catch (const compile_error& e)
- {
- termcolor::setBright(termcolor::RED);
- std::cerr << "*** Error compiling:\n" << e.what();
- termcolor::reset();
- return 1;
- }
- catch (const std::exception& e)
- {
- termcolor::setBright(termcolor::RED);
- std::cerr << e.what() << std::endl;
- termcolor::reset();
- return 1;
- }
-
- return 0;
-}
-
-void runTest(const char* path)
-{
- /*
- std::string line;
- g_shell->out() << "echo Hello world\n" << std::flush;
- std::getline(g_shell->in(), line);
-
- termcolor::set(termcolor::RED);
- std::cout << line << std::endl;
- termcolor::reset();
- */
-
- std::stringstream cmd;
- std::string binary;
- std::string out, err;
- std::string dirname, filename = "/tmp/darlingtest-";
- int rv;
-
- filename += getenv("USER");
- filename += '/';
- dirname = filename;
- filename += uniqueName(path);
-
- mkdir(dirname.c_str(), 0700);
-
- binary = stripext(filename);
-
- termcolor::set(termcolor::WHITE, termcolor::BLACK, termcolor::DIM);
-
- std::cout << "Uploading " << path << "...\n";
- try
- {
- g_sftp->mkdir(dirname.c_str(), 0700);
- } catch (...) {}
- // upload the source code
- g_sftp->upload(path, filename);
-
- try
- {
- std::cout << "Compiling...\n";
- // compile the code remotely
- cmd << compiler(path) << ' ' << cflags(path) << filename << " -o " << binary;
- rv = g_ssh->runCommand(cmd.str(), out, err);
-
- if (rv)
- throw compile_error(err);
-
- std::cout << "Running remotely...\n";
- // run the program remotely
- rv = g_ssh->runCommand(binary, out, err);
-
- if (rv)
- throw nonzero_exit_error(true, out);
-
- std::cout << "Downloading...\n";
- // download the Mach-O executable
- g_sftp->download(binary, binary);
-
- std::cout << "Running locally...\n";
- // run the executable via dyld
- std::stringstream locOut;
- pstream* loc = pstream::popen(std::string(DYLD_COMMAND) + " " + binary);
-
- locOut << loc;
-
- rv = loc->wait();
-
- if (rv)
- throw nonzero_exit_error(false, locOut.str());
-
- if (locOut.str() != out)
- throw different_output_error(out, locOut.str());
-
- // clean up locally
- unlink(binary.c_str());
-
- try
- {
- // clean up remotely
- g_sftp->unlink(binary);
- g_sftp->unlink(filename);
- }
- catch (...) {}
-
- }
- catch (...)
- {
- // clean up locally
- unlink(binary.c_str());
-
- try
- {
- // clean up remotely
- g_sftp->unlink(binary);
- g_sftp->unlink(filename);
- }
- catch (...) {}
-
- throw;
- }
-}
-
-std::string cflags(const char* path)
-{
- std::string cflags;
- const char* suffix = strrchr(path, '.');
- if (!suffix)
- throw std::runtime_error("Unsupported file name");
-
- if (!strcmp(DYLD_COMMAND, "dyld32") || sizeof(void*) == 4)
- cflags += "-m32 ";
-
- if (!strcmp(suffix, ".m") || !strcmp(suffix, ".mm"))
- cflags += "-lobjc ";
-
- std::ifstream f(path);
- std::string first;
-
- std::getline(f, first);
- if (first.compare(0, 11, "// CFLAGS: ") == 0)
- {
- cflags += first.substr(11);
- cflags += ' ';
- }
-
- return cflags;
-}
-
-const char* compiler(const char* path)
-{
- const char* suffix = strrchr(path, '.');
- if (!suffix)
- throw std::runtime_error("Unsupported file name");
-
- if (!strcmp(suffix, ".c") || !strcmp(suffix, ".m"))
- return "clang";
- else if (!strcmp(suffix, ".cpp") || !strcmp(suffix, ".mm"))
- return "clang++";
- else
- throw std::runtime_error("Unsupported file name");
-}
-
-
-std::string uniqueName(const std::string& path)
-{
- char* name = new char[path.size()+1];
- strcpy(name, path.c_str());
-
- std::stringstream out;
- out << getpid() << '.';
- out << basename(name);
-
- delete [] name;
- return out.str();
-}
-
-void bits(const char* progname)
-{
- char* arg0 = strdup(progname);
- char* cmd = basename(arg0);
-
- termcolor::set(termcolor::WHITE, termcolor::BLACK, termcolor::DIM);
- if (!strcmp(cmd, "runtest64"))
- {
- std::cout << "Running in 64-bit mode.\n";
- DYLD_COMMAND = "dyld64";
- }
- else if (!strcmp(cmd, "runtest32"))
- {
- std::cout << "Running in 32-bit mode.\n";
- DYLD_COMMAND = "dyld32";
- }
- termcolor::reset();
-
- free(arg0);
-}
-
-std::string stripext(std::string file)
-{
- size_t pos = file.rfind('.');
- if (pos == std::string::npos)
- return file;
- return file.substr(0, pos);
-}
-
diff --git a/tests/runtest32 b/tests/runtest32
deleted file mode 120000
index 41dd14534..000000000
--- a/tests/runtest32
+++ /dev/null
@@ -1 +0,0 @@
-runtest
\ No newline at end of file
diff --git a/tests/runtest64 b/tests/runtest64
deleted file mode 120000
index 41dd14534..000000000
--- a/tests/runtest64
+++ /dev/null
@@ -1 +0,0 @@
-runtest
\ No newline at end of file
diff --git a/tests/termcolor.cpp b/tests/termcolor.cpp
deleted file mode 100644
index 67cf161b6..000000000
--- a/tests/termcolor.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "termcolor.h"
-#include
-#include
-
-const bool isTty = isatty(1) != 0;
-
-void termcolor::set(int text, int bg, int attrib)
-{
- if (!isTty)
- return;
-
- std::cout << "\x1b[" << attrib << ';' << (text + 30) << ';' << (bg + 40) << 'm' << std::flush;
-}
-
diff --git a/tests/termcolor.h b/tests/termcolor.h
deleted file mode 100644
index bf6d080d3..000000000
--- a/tests/termcolor.h
+++ /dev/null
@@ -1,31 +0,0 @@
-#ifndef TERMCOLOR_H
-#define TERMCOLOR_H
-
-namespace termcolor
-{
-
-const int RESET = 0;
-const int BRIGHT = 1;
-const int DIM = 2;
-const int UNDERLINE = 3;
-const int BLINK = 4;
-const int REVERSE = 7;
-const int HIDDEN = 8;
-
-const int BLACK = 0;
-const int RED = 1;
-const int GREEN = 2;
-const int YELLOW = 3;
-const int BLUE = 4;
-const int MAGENTA = 5;
-const int CYAN = 6;
-const int WHITE = 7;
-
-void set(int text, int bg = BLACK, int attrib = RESET);
-inline void setBright(int text, int bg = BLACK) { set(text, bg, BRIGHT); }
-inline void reset() { set(WHITE); }
-
-}
-
-#endif
-
diff --git a/tests/timer.cpp b/tests/timer.cpp
deleted file mode 100644
index 0eb9f0157..000000000
--- a/tests/timer.cpp
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "timer.h"
-
-void timer::start()
-{
- m_start = ::time(nullptr);
-}
-
-int timer::stop()
-{
- return ::time(nullptr) - m_start;
-}
-
diff --git a/tests/timer.h b/tests/timer.h
deleted file mode 100644
index c6e0702f9..000000000
--- a/tests/timer.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef TIMER_H
-#define TIMER_H
-#include
-
-class timer
-{
-public:
- void start();
- int stop();
-private:
- time_t m_start;
-};
-
-#endif
-