Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Feb 13, 2017
1 parent 90208d6 commit 947075a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end

desc "run all tests"
Rake::Task["test"].clear
task test: ["test:bintest"]
task test: ["test:bintest", "test:mtest"]

desc "cleanup"
task :clean do
Expand Down
8 changes: 4 additions & 4 deletions bintest/acli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

BIN_PATH = File.join(File.dirname(__FILE__), "../mruby/bin/acli")

assert("hello") do
output, status = Open3.capture2(BIN_PATH)
assert("with invalid url") do
output, status = Open3.capture2(BIN_PATH, "-u", "localhost:0:1:2")

assert_true status.success?, "Process did not exit cleanly"
assert_include output, "Hello World"
assert_false status.success?, "Process exited cleanly"
assert_include output, "Error: "
end

assert("version") do
Expand Down
13 changes: 9 additions & 4 deletions build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ def gem_config(conf)
MRuby::Build.new do |conf|
toolchain :clang

# conf.enable_bintest
# conf.enable_debug
# conf.enable_test
conf.enable_bintest
conf.enable_debug
conf.enable_test

# C compiler settings
conf.cc do |cc|
if RUBY_PLATFORM =~ /darwin/i
cc.include_paths << %w(/usr/local/include /usr/local/opt/openssl/include)
linker.library_paths << %w(/usr/local/lib /usr/local/opt/openssl/lib)

else
cc.flags << [ENV['CFLAGS'] || %w(-fPIC -DHAVE_ARPA_INET_H)]
cc.include_paths << %(/root/wslay/lib)
Expand Down Expand Up @@ -60,6 +59,12 @@ def gem_config(conf)
MRuby::CrossBuild.new("i686-pc-linux-gnu") do |conf|
toolchain :gcc

# C compiler settings
conf.cc do |cc|
cc.flags << [ENV['CFLAGS'] || %w(-fPIC -DHAVE_ARPA_INET_H)]
cc.include_paths << %(/root/wslay/lib)
end

[conf.cc, conf.cxx, conf.linker].each do |cc|
cc.flags << "-m32"
end
Expand Down
8 changes: 8 additions & 0 deletions mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ MRuby::Gem::Specification.new("acli") do |spec|
spec.bins = ["acli"]

spec.add_dependency "mruby-exit", core: "mruby-exit"
spec.add_dependency "mruby-string-ext", core: "mruby-string-ext"
spec.add_dependency "mruby-hash-ext", core: "mruby-hash-ext"
spec.add_dependency "mruby-kernel-ext", core: "mruby-kernel-ext"
spec.add_dependency "mruby-struct", core: "mruby-struct"

spec.add_dependency "mruby-json", mgem: "mruby-json"
spec.add_dependency "mruby-regexp-pcre", mgem: "mruby-regexp-pcre"
spec.add_dependency "mruby-uri-parser", mgem: "mruby-uri-parser"
spec.add_dependency "mruby-getopts", mgem: "mruby-getopts"

spec.add_dependency "mruby-websockets", github: "palkan/mruby-websockets", branch: "no-tls"

spec.add_test_dependency "mruby-mtest", mgem: "mruby-mtest"
end
47 changes: 47 additions & 0 deletions test/test_commands.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Acli
class TestCommands < MTest::Unit::TestCase
class TestClient
attr_reader :identifier

def initialize(identifier = "test")
@identifier = identifier
end

def close
@closed = true
end

def closed?
@closed == true
end
end

def client
@client ||= TestClient.new
end

def test_quit
subject = Commands.new(client)
subject.prepare_command "\\q"
assert client.closed?
end

def test_subscribe
subject = Commands.new(client)
assert_equal(
"{\"command\":\"subscribe\",\"identifier\":\"{\\\"id\\\":2,\\\"channel\\\":\\\"chat\\\"}\"}",
subject.prepare_command("\\s chat id:2")
)
end

def test_perform
subject = Commands.new(client)
assert_equal(
"{\"command\":\"message\",\"identifier\":\"test\",\"data\":\"{\\\"message\\\":\\\"Hello!\\\",\\\"sid\\\":123,\\\"action\\\":\\\"speak\\\"}\"}",
subject.prepare_command("\\p speak message:\"Hello!\" sid:123")
)
end
end
end

MTest::Unit.new.run

0 comments on commit 947075a

Please sign in to comment.