From d000b46474ff6ec34eaa7237263a10f1b1c03d2d Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Thu, 10 Jan 2019 10:27:35 +1100 Subject: [PATCH 1/4] Run Crytic against the shard on CI --- .travis.yml | 1 + Makefile | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3751d20..f74dec4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,4 @@ install: script: - crystal spec + - bin/crytic --preamble "" diff --git a/Makefile b/Makefile index 53ff128..095f28b 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -12,5 +12,11 @@ clean: check: crystal build --no-codegen src/**/*.cr -test: +deps: + shards install + +test: deps crystal spec + +crytic: deps + bin/crytic --preamble "" From fe08523f4d55d8e51787b5e4d3453f5e6ca13628 Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Thu, 10 Jan 2019 10:38:48 +1100 Subject: [PATCH 2/4] Parallelize specs a little --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 095f28b..909421d 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ deps: shards install test: deps - crystal spec + crystal spec -- -p 3 crytic: deps bin/crytic --preamble "" From f813266bfe03289e24db2c99933d8f99ae9c0c72 Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Thu, 10 Jan 2019 11:23:47 +1100 Subject: [PATCH 3/4] Add extra tests for text extensions --- .../resolvers/directory_resolver_spec.cr | 18 +++++++++-------- spec/resources/example_directory/.gophermap | 20 +++++++++++++++++++ spec/resources/example_directory/test.c | 0 spec/resources/example_directory/test.cpp | 0 spec/resources/example_directory/test.cr | 0 spec/resources/example_directory/test.cs | 0 spec/resources/example_directory/test.d | 0 spec/resources/example_directory/test.el | 0 spec/resources/example_directory/test.fs | 0 spec/resources/example_directory/test.html | 0 spec/resources/example_directory/test.js | 0 .../resources/example_directory/test.markdown | 0 spec/resources/example_directory/test.md | 0 spec/resources/example_directory/test.py | 0 spec/resources/example_directory/test.rb | 0 spec/resources/example_directory/test.rtf | 0 spec/resources/example_directory/test.sh | 0 spec/resources/example_directory/test.txt | 0 spec/resources/example_directory/test.xml | 0 src/gopher/resolvers/directory_resolver.cr | 2 +- 20 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 spec/resources/example_directory/test.c create mode 100644 spec/resources/example_directory/test.cpp create mode 100644 spec/resources/example_directory/test.cr create mode 100644 spec/resources/example_directory/test.cs create mode 100644 spec/resources/example_directory/test.d create mode 100644 spec/resources/example_directory/test.el create mode 100644 spec/resources/example_directory/test.fs create mode 100644 spec/resources/example_directory/test.html create mode 100644 spec/resources/example_directory/test.js create mode 100644 spec/resources/example_directory/test.markdown create mode 100644 spec/resources/example_directory/test.md create mode 100644 spec/resources/example_directory/test.py create mode 100644 spec/resources/example_directory/test.rb create mode 100644 spec/resources/example_directory/test.rtf create mode 100644 spec/resources/example_directory/test.sh create mode 100644 spec/resources/example_directory/test.txt create mode 100644 spec/resources/example_directory/test.xml diff --git a/spec/gopher/resolvers/directory_resolver_spec.cr b/spec/gopher/resolvers/directory_resolver_spec.cr index f83cee7..f373203 100644 --- a/spec/gopher/resolvers/directory_resolver_spec.cr +++ b/spec/gopher/resolvers/directory_resolver_spec.cr @@ -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 diff --git a/spec/resources/example_directory/.gophermap b/spec/resources/example_directory/.gophermap index d0fea51..ea6cc7a 100644 --- a/spec/resources/example_directory/.gophermap +++ b/spec/resources/example_directory/.gophermap @@ -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% diff --git a/spec/resources/example_directory/test.c b/spec/resources/example_directory/test.c new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.cpp b/spec/resources/example_directory/test.cpp new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.cr b/spec/resources/example_directory/test.cr new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.cs b/spec/resources/example_directory/test.cs new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.d b/spec/resources/example_directory/test.d new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.el b/spec/resources/example_directory/test.el new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.fs b/spec/resources/example_directory/test.fs new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.html b/spec/resources/example_directory/test.html new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.js b/spec/resources/example_directory/test.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.markdown b/spec/resources/example_directory/test.markdown new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.md b/spec/resources/example_directory/test.md new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.py b/spec/resources/example_directory/test.py new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.rb b/spec/resources/example_directory/test.rb new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.rtf b/spec/resources/example_directory/test.rtf new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.sh b/spec/resources/example_directory/test.sh new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.txt b/spec/resources/example_directory/test.txt new file mode 100644 index 0000000..e69de29 diff --git a/spec/resources/example_directory/test.xml b/spec/resources/example_directory/test.xml new file mode 100644 index 0000000..e69de29 diff --git a/src/gopher/resolvers/directory_resolver.cr b/src/gopher/resolvers/directory_resolver.cr index 7846d07..01bec13 100644 --- a/src/gopher/resolvers/directory_resolver.cr +++ b/src/gopher/resolvers/directory_resolver.cr @@ -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) From d942f250c060a858eabb484e786e217e786650cb Mon Sep 17 00:00:00 2001 From: Andy Nicholson Date: Sat, 12 Jan 2019 15:32:24 +1100 Subject: [PATCH 4/4] Added mutation specs for the resolver --- spec/gopher/resolver_spec.cr | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 spec/gopher/resolver_spec.cr diff --git a/spec/gopher/resolver_spec.cr b/spec/gopher/resolver_spec.cr new file mode 100644 index 0000000..09b3b37 --- /dev/null +++ b/spec/gopher/resolver_spec.cr @@ -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