Skip to content
This repository has been archived by the owner on Sep 4, 2019. It is now read-only.

Commit

Permalink
Merge pull request #28 from JuliaLang/testrefactor
Browse files Browse the repository at this point in the history
Test modernized, Travis, Coveralls/Coverage, close #27
  • Loading branch information
IainNZ committed Aug 27, 2014
2 parents d035f6c + 2c839b1 commit d23805c
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 33 deletions.
35 changes: 16 additions & 19 deletions .travis.yml
@@ -1,24 +1,21 @@
language: cpp
compiler:
- clang
- clang
notifications:
email:
- zach.allaun@gmail.com
- daniel@danielespeset.com
email: false
env:
- JULIAVERSION="juliareleases"
- JULIAVERSION="julianightlies"
before_install:
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/julianightlies -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
- git config --global user.name "Zach Allaun"
- git config --global user.email "zach.allaun@gmail.com"
- git submodule update --init --recursive
- sudo add-apt-repository ppa:staticfloat/julia-deps -y
- sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
- sudo apt-get update -qq -y
- sudo apt-get install libpcre3-dev julia -y
- git config --global user.name "Travis User"
- git config --global user.email "travis@example.net"
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
script:
- julia -e "Pkg.init()"
- mkdir -p ~/.julia/HttpServer
- cp -R ./* ~/.julia/HttpServer/
- julia -e 'Pkg.add("BinDeps")'
- julia -e 'Pkg.add("FactCheck")'
- julia -e 'Pkg.add("HttpCommon")'
- julia -e 'Pkg.add("Calendar")'
- julia ~/.julia/HttpServer/test/test.jl
- julia -e 'Pkg.init(); Pkg.clone(pwd())'
- julia -e 'Pkg.test("HttpServer", coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("HttpServer")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
22 changes: 12 additions & 10 deletions README.md
@@ -1,6 +1,7 @@
# HttpServer.jl

[![Build Status](https://travis-ci.org/hackerschool/HttpServer.jl.png)](https://travis-ci.org/hackerschool/HttpServer.jl)
[![Build Status](https://travis-ci.org/JuliaLang/HttpServer.jl.svg?branch=master)](https://travis-ci.org/JuliaLang/HttpServer.jl)
[![Coverage Status](https://img.shields.io/coveralls/JuliaLang/HttpServer.jl.svg)](https://coveralls.io/r/JuliaLang/HttpServer.jl)

This is a basic, non-blocking HTTP server in Julia.

Expand All @@ -9,18 +10,19 @@ if you're happy dealing with values representing HTTP requests and responses dir
For a higher-level view, you could use [Meddle](https://github.com/hackerschool/Meddle.jl) or [Morsel](https://github.com/hackerschool/Morsel.jl).
If you'd like to use WebSockets as well, you'll need to grab [WebSockets.jl](https://github.com/hackerschool/WebSockets.jl).

## Installation/Setup
**Installation**: `Pkg.add("HttpServer")`

```jl
Pkg.add("HttpServer")
To make sure everything is working, you can run
```

To make sure everything is working, you can run `cd ~/.julia/HttpServer` and `julia examples/hello.jl`. If you open up `localhost:8000/hello/name/`, you should get a greeting from the server.
cd ~/.julia/v0.3/HttpServer
julia examples/hello.jl
```
If you open up `localhost:8000/hello/name/` in your browser, you should get a greeting from the server.


## Basic Example:

~~~~.jl
```julia
using HttpServer

http = HttpHandler() do req::Request, res::Response
Expand All @@ -32,9 +34,9 @@ http.events["listen"] = ( port ) -> println("Listening on $port...")

server = Server( http )
run( server, 8000 )
~~~~
```

~~~~
```
:::::::::::::
:: ::
:: Made at ::
Expand All @@ -43,4 +45,4 @@ run( server, 8000 )
::
Hacker School
:::::::::::::
~~~~
```
6 changes: 3 additions & 3 deletions REQUIRE
@@ -1,4 +1,4 @@
julia 0.2-
HttpCommon 0.0.3-
HttpParser 0.0.5-
julia 0.3
HttpCommon
HttpParser
GnuTLS
2 changes: 2 additions & 0 deletions test/REQUIRE
@@ -0,0 +1,2 @@
FactCheck
Requests
27 changes: 26 additions & 1 deletion test/test.jl → test/runtests.jl
@@ -1,6 +1,6 @@
using HttpCommon
using FactCheck
import HttpServer
using HttpServer

facts("HttpServer utility functions") do
context("HttpServer.write does sensible things") do
Expand All @@ -19,3 +19,28 @@ facts("HttpServer utility functions") do
@fact grep(vals, "Hello") => "Hello World!"
end
end

import Requests

facts("HttpServer run") do
context("HttpServer can run the example") do
http = HttpHandler() do req::Request, res::Response
Response( ismatch(r"^/hello/",req.resource) ? string("Hello ", split(req.resource,'/')[3], "!") : 404 )
end
http.events["error"] = (client, err) -> println(err)
http.events["listen"] = (port ) -> println("Listening on $port...")

server = Server(http)
@async run(server, 8000)
sleep(1.0)

ret = Requests.get("http://localhost:8000/hello/travis")
@fact ret.data => "Hello travis!"
@fact ret.status => 200

ret = Requests.get("http://localhost:8000/bad")
@fact ret.data => ""
@fact ret.status => 404
end
end

1 comment on commit d23805c

@jiahao
Copy link

@jiahao jiahao commented on d23805c Aug 27, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

I've updated the testing config in Example.jl also.

Please sign in to comment.