Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More comprehensive CI #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ install:

script:
- crystal spec
- bin/crytic --preamble ""
12 changes: 9 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PHONY: app-container clean check test
PHONY: app-container clean check test deps crytic

CR_FLAGS="--release --static --no-debug -Dtrace"
PUBLIC_PORT=9000
Expand All @@ -12,5 +12,11 @@ clean:
check:
crystal build --no-codegen src/**/*.cr

test:
crystal spec
deps:
shards install

test: deps
crystal spec -- -p 3

crytic: deps
bin/crytic --preamble ""
24 changes: 24 additions & 0 deletions spec/gopher/resolver_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require "../spec_helper"

class SpecResolver < Gopher::Resolver
def resolve(_req)
Gopher::Response.error("BOOM")
end

def menu_entry_type
Gopher::MenuEntryType::Error
end
end

module Gopher
describe Resolver do
describe "default values" do
it "are correct" do
resolver = SpecResolver.new

expect(resolver.default_host).must_equal("localhost")
expect(resolver.default_port).must_equal(70_u16)
end
end
end
end
18 changes: 10 additions & 8 deletions spec/gopher/resolvers/directory_resolver_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ module Gopher
expect(menu.entries.size > 0).must_equal(true)
end

it "lists .txt files as text entries" do
result = dr.resolve(req)
menu = result.value.as Menu
it "lists text files as text entries" do
DirectoryResolver::TEXT_EXTENSIONS.each do |ext|
result = dr.resolve(req)
menu = result.value.as Menu

ipsum = menu.entries.count do |entry|
entry.entry_type == MenuEntryType::TextFile &&
entry.selector == "/1files/0ipsum.txt"
end
ipsum = menu.entries.count do |entry|
entry.entry_type == MenuEntryType::TextFile &&
entry.selector == "/1files/0test#{ext}"
end

expect(ipsum).must_equal(1)
expect(ipsum).must_equal(1)
end
end

it "includes submenus" do
Expand Down
20 changes: 20 additions & 0 deletions spec/resources/example_directory/.gophermap
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,23 @@ i
0Hipster Ipsum 0ipsum.txt %HOST% %PORT%
1Games /1games %HOST% %PORT%
1Other Directory /1looks_like_a_file_but_is_a.directory %HOST% %PORT%
i Test text files:
0c 0test.c %HOST% %PORT%
0C 0test.C %HOST% %PORT%
0cpp 0test.cpp %HOST% %PORT%
0cs 0test.cs %HOST% %PORT%
0cr 0test.cr %HOST% %PORT%
0d 0test.d %HOST% %PORT%
0el 0test.el %HOST% %PORT%
0fs 0test.fs %HOST% %PORT%
0html 0test.html %HOST% %PORT%
0xml 0test.xml %HOST% %PORT%
0json 0test.json %HOST% %PORT%
0txt 0test.txt %HOST% %PORT%
0md 0test.md %HOST% %PORT%
0markdown 0test.markdown %HOST% %PORT%
0rb 0test.rb %HOST% %PORT%
0py 0test.py %HOST% %PORT%
0sh 0test.sh %HOST% %PORT%
0rtf 0test.rtf %HOST% %PORT%
0js 0test.js %HOST% %PORT%
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion src/gopher/resolvers/directory_resolver.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Gopher
PORT_MARKER = "%PORT%"
IMAGE_EXTENSIONS = [".jpg", ".gif", ".bmp", ".png", ".jpeg", ".tif", ".tiff", ".tga", ".ico"]
BINARY_EXTENSIONS = IMAGE_EXTENSIONS + [".zip", ".tar", ".gz", ".bz2", ".doc", ".xls", ".ppt", ".exe", ".wav", ".mp3", ".ogg"]
TEXT_EXTENSIONS = [".c", ".C", ".cpp", ".cs", ".cr", ".d", ".el", ".fs", ".html", ".xml", ".json", ".txt", ".md", ".markdown", ".rb", ".py", ".sh", ".js", ".rtf"]
TEXT_EXTENSIONS = [".c", ".cpp", ".cs", ".cr", ".d", ".el", ".fs", ".html", ".xml", ".json", ".txt", ".md", ".markdown", ".rb", ".py", ".sh", ".js", ".rtf"]

def initialize(@root_path : String, @root_selector : String, config)
super(config)
Expand Down