Skip to content

Commit

Permalink
#83 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Dec 7, 2017
1 parent 0883b48 commit d2d67cb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 31 deletions.
3 changes: 0 additions & 3 deletions bin/pdd
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,3 @@ rescue StandardError => ex
puts "#{Rainbow('ERROR').red} (#{ex.class.name}): #{ex.message}"
exit(-1)
end

# @todo xx

18 changes: 9 additions & 9 deletions lib/pdd/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ def puzzles
lines = File.readlines(@file)
lines.each_with_index do |line, idx|
begin
/[^\s]@todo/.match(line) do |_|
raise Error, 'TODO must have a leading space to become a puzzle, \
as this page explains: https://github.com/yegor256/pdd#how-to-format'
/[^\s]\x40todo/.match(line) do |_|
raise Error, "\x40todo must have a leading space to become \
a puzzle, as this page explains: https://github.com/yegor256/pdd#how-to-format"
end
/@todo(?!\s+#)/.match(line) do |_|
raise Error, "@todo found, but puzzle can't be parsed, \
most probably because TODO is not followed by a puzzle marker, as this page \
explains: https://github.com/yegor256/pdd#how-to-format"
/\x40todo(?!\s+#)/.match(line) do |_|
raise Error, "\x40todo found, but puzzle can't be parsed, \
most probably because \x40todo is not followed by a puzzle marker, \
as this page explains: https://github.com/yegor256/pdd#how-to-format"
end
%r{(.*(?:^|\s))@todo\s+#([\w\-\.:/]+)\s+(.+)}.match(line) do |match|
puzzles << puzzle(lines.drop(idx + 1), match, idx)
%r{(.*(?:^|\s))\x40todo\s+#([\w\-\.:/]+)\s+(.+)}.match(line) do |m|
puzzles << puzzle(lines.drop(idx + 1), m, idx)
end
rescue Error, ArgumentError => ex
raise Error, "puzzle at line ##{idx + 1}; #{ex.message}"
Expand Down
6 changes: 3 additions & 3 deletions test/test_pdd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TestPDD < Minitest::Test
def test_basic
Dir.mktmpdir 'test' do |dir|
opts = opts(['-q', '-s', dir, '-e', '**/*.png', '-r', 'max-estimate:15'])
File.write(File.join(dir, 'a.txt'), '@todo #55 hello!')
File.write(File.join(dir, 'a.txt'), "\x40todo #55 hello!")
matches(
Nokogiri::XML(PDD::Base.new(opts).xml),
[
Expand All @@ -49,7 +49,7 @@ def test_basic
def test_rules_failure
Dir.mktmpdir 'test' do |dir|
opts = opts(['-q', '-s', dir, '-e', '**/*.png', '-r', 'min-estimate:30'])
File.write(File.join(dir, 'a.txt'), '@todo #90 hello!')
File.write(File.join(dir, 'a.txt'), "\x40todo #90 hello!")
assert_raises PDD::Error do
PDD::Base.new(opts).xml
end
Expand All @@ -70,7 +70,7 @@ def test_git_repo
cd 'a long dir name'
mkdir 'a kid'
cd 'a kid'
echo '@todo #1 this is some puzzle' > '.это файл.txt'
echo '\x40todo #1 this is some puzzle' > '.это файл.txt'
cd ../..
git add -f .
git commit --quiet -am 'first version'
Expand Down
32 changes: 16 additions & 16 deletions test/test_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ def test_parsing
File.write(
file,
"
* @todo #44 hello,
* \x40todo #44 hello,
* how are you\t\r\tdoing?
* -something else
Something else
~~ @todo #ABC-3 this is another puzzle
~~ \x40todo #ABC-3 this is another puzzle
~~ and it also has to work
"
)
Expand All @@ -59,10 +59,10 @@ def test_failing_on_invalid_puzzle
file = File.join(dir, 'a.txt')
File.write(
file,
'
* @todo #44 this is an incorrectly formatted puzzle,
"
* \x40todo #44 this is an incorrectly formatted puzzle,
* with a second line without a leading space
'
"
)
error = assert_raises PDD::Error do
PDD::VerboseSource.new(file, PDD::Source.new(file, 'hey')).puzzles
Expand All @@ -76,22 +76,22 @@ def test_failing_on_incomplete_puzzle
file = File.join(dir, 'ff.txt')
File.write(
file,
'
* @todo this puzzle misses ticket name/number
'
"
* \x40todo this puzzle misses ticket name/number
"
)
error = assert_raises PDD::Error do
PDD::VerboseSource.new(file, PDD::Source.new(file, 'ff')).puzzles
end
assert !error.to_s.index('TODO is not followed by a puzzle marker').nil?
assert !error.to_s.index("\x40todo is not followed by").nil?
end
end

def test_failing_on_broken_unicode
skip if Gem.win_platform?
Dir.mktmpdir 'test' do |dir|
file = File.join(dir, 'xx.txt')
File.write(file, ' * @todo #44 this is a broken unicode: ' + 0x92.chr)
File.write(file, ' * \x40todo #44 this is a broken unicode: ' + 0x92.chr)
assert_raises PDD::Error do
PDD::VerboseSource.new(file, PDD::Source.new(file, 'xx')).puzzles
end
Expand All @@ -105,7 +105,7 @@ def test_failing_on_invalid_puzzle_without_hash_sign
File.write(
file,
'
* @todo 44 this puzzle is not formatted correctly
* \x40todo 44 this puzzle is not formatted correctly
'
)
error = assert_raises PDD::Error do
Expand All @@ -120,14 +120,14 @@ def test_failing_on_puzzle_without_leading_space
file = File.join(dir, 'hey.txt')
File.write(
file,
'
*@todo #999 this is an incorrectly formatted puzzle!
'
"
*\x40todo #999 this is an incorrectly formatted puzzle!
"
)
error = assert_raises PDD::Error do
PDD::VerboseSource.new(file, PDD::Source.new(file, 'x')).puzzles
end
assert !error.message.index('TODO must have a leading space').nil?
assert !error.message.index("\x40todo must have a leading space").nil?
end
end

Expand All @@ -140,7 +140,7 @@ def test_reads_git_author
git init --quiet .
git config user.email [email protected]
git config user.name test
echo '@todo #1 this is the puzzle' > a.txt
echo '\x40todo #1 this is the puzzle' > a.txt
git add a.txt
git commit --quiet -am 'first version'
")
Expand Down

1 comment on commit d2d67cb

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on d2d67cb Dec 7, 2017

Choose a reason for hiding this comment

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

I wasn't able to retrieve PDD puzzles from the code base and submit them to GitHub. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x;set -e;set -o pipefail;cd /tmp/0pdd20171207-4-1mxgdao/yegor256/pdd && git config --local core.autocrlf false && git reset --hard --quiet && git clean --force -d && git fetch --quiet && git checkout master && git rebase --abort || true && git rebase --strategy-option=theirs origin/master:...

Please, copy and paste this stack trace to GitHub:

RuntimeError
set -x;set -e;set -o pipefail;cd /tmp/0pdd20171207-4-1mxgdao/yegor256/pdd && git config --local core.autocrlf false && git reset --hard --quiet && git clean --force -d && git fetch --quiet && git checkout master && git rebase --abort || true && git rebase --strategy-option=theirs origin/master: pid 22391 exit 1 (not zero):
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20171207-4-1mxgdao/yegor256/pdd
+ git config --local core.autocrlf false
+ git reset --hard --quiet
+ git clean --force -d
+ git fetch --quiet
+ git checkout master
Already on 'master'
+ git rebase --abort
No rebase in progress?
+ true
+ git rebase --strategy-option=theirs origin/master
Cannot rebase: You have unstaged changes.
Please commit or stash them.

M	test_assets/favicon.ico
Your branch is behind 'origin/master' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

/app/objects/exec.rb:41:in `block in run'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/open3.rb:205:in `popen_run'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/open3.rb:95:in `popen3'
/app/objects/exec.rb:39:in `run'
/app/objects/git_repo.rb:103:in `pull'
/app/objects/git_repo.rb:68:in `push'
/app/objects/job.rb:35:in `proceed'
/app/objects/job_starred.rb:33:in `proceed'
/app/objects/job_recorded.rb:32:in `proceed'
/app/objects/job_emailed.rb:35:in `proceed'
/app/objects/job_commiterrors.rb:36:in `proceed'
/app/objects/job_detached.rb:49:in `block in exclusive'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:91:in `block in timeout'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `block in catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:33:in `catch'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/timeout.rb:106:in `timeout'
/app/objects/job_detached.rb:47:in `exclusive'
/app/objects/job_detached.rb:37:in `block in proceed'
/app/objects/job_detached.rb:37:in `fork'
/app/objects/job_detached.rb:37:in `proceed'
/app/0pdd.rb:351:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1632:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1632:in `block in compile!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:991:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1010:in `route_eval'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:991:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1037:in `block in process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1035:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1035:in `process_route'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:989:in `block in route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:988:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:988:in `route!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1094:in `block in dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1091:in `dispatch!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:923:in `block in call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `block in invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `catch'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1073:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:923:in `call!'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:913:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/xss_header.rb:18:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/path_traversal.rb:16:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/json_csrf.rb:26:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/base.rb:50:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-protection-2.0.0/lib/rack/protection/frame_options.rb:31:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/logger.rb:15:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/common_logger.rb:33:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:231:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/method_override.rb:22:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:194:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1955:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1499:in `block in call'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1726:in `synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/sinatra-2.0.0/lib/sinatra/base.rb:1499:in `call'
/app/vendor/bundle/ruby/2.3.0/gems/rack-2.0.3/lib/rack/handler/webrick.rb:86:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
/app/vendor/ruby-2.3.3/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Please sign in to comment.