diff --git a/Formula/cppcms.rb b/Formula/cppcms.rb new file mode 100644 index 0000000000..ce4231ea6e --- /dev/null +++ b/Formula/cppcms.rb @@ -0,0 +1,86 @@ +class Cppcms < Formula + desc "A Free High Performance Web Development Framework" + homepage "http://cppcms.com/wikipp/en/page/main" + url "https://downloads.sourceforge.net/project/cppcms/cppcms/1.0.5/cppcms-1.0.5.tar.bz2" + sha256 "84b685977bca97c3e997497f227bd5906adb80555066d811a7046b01c2f51865" + + depends_on "cmake" => :build + depends_on "pcre" + depends_on "openssl" + needs :cxx11 + + def install + ENV.cxx11 + system "cmake", *std_cmake_args + system "make", "install" + end + + test do + (testpath/"hello.cpp").write <<-EOS.undent + #include + #include + #include + #include + #include + #include + + class hello : public cppcms::application { + public: + hello(cppcms::service& srv): cppcms::application(srv) {} + virtual void main(std::string url); + }; + + void hello::main(std::string /*url*/) + { + response().out() << + "\\n" + "\\n" + "

Hello World

\\n" + "\\n" + "\\n"; + } + + int main(int argc,char ** argv) + { + try { + cppcms::service srv(argc,argv); + srv.applications_pool().mount( + cppcms::applications_factory() + ); + srv.run(); + return 0; + } + catch(std::exception const &e) { + std::cerr << e.what() << std::endl; + return -1; + } + } + EOS + + (testpath/"config.json").write <<-EOS.undent + { + "service" : { + "api" : "http", + "port" : 8080, + "worker_threads": 1 + }, + "daemon" : { + "enable" : false + }, + "http" : { + "script_names" : [ "/hello" ] + } + } + EOS + system ENV.cxx, "-o", "hello", "-std=c++11", "-stdlib=libc++", "-lc++", "-lcppcms", "hello.cpp" + pid = fork { exec "./hello", "-c", "config.json" } + + sleep 1 # grace time for server start + begin + assert_match /Hello World/, shell_output("curl http://127.0.0.1:8080/hello") + ensure + Process.kill 9, pid + Process.wait pid + end + end +end