From 2814baefc7a7faa967873e6b8a7f6c111c4e7fd2 Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Thu, 18 Jan 2024 23:55:24 -0500 Subject: [PATCH] [#222] Ignore comments from .gitignore file and enable tests for --skip-gitignore option --- bin/pdd | 3 +- features/cli.feature | 51 +++++++++++++++++++++++++++--- features/step_definitions/steps.rb | 2 +- 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/bin/pdd b/bin/pdd index d4d30df..7238f11 100755 --- a/bin/pdd +++ b/bin/pdd @@ -87,7 +87,8 @@ https://github.com/cqfn/pdd/blob/master/README.md" if opts['skip-gitignore'] && File.exist?('.gitignore') cfg = File.new('.gitignore') - body = File.read(cfg) + body = '' + File.foreach(cfg) { |line| body << line unless line.start_with?('#') } extra = body.split(/\s+/).map(&:strip) opts['skip-gitignore'] = extra PDD.log.info "Found #{body.split("\n").length} lines in #{File.absolute_path(cfg)}" diff --git a/features/cli.feature b/features/cli.feature index aa7a6ca..799271d 100644 --- a/features/cli.feature +++ b/features/cli.feature @@ -64,15 +64,14 @@ Feature: Command Line Processing Then Exit code is zero And XML file "out.xml" matches "/puzzles[count(puzzle)=0]" - Scenario: Excluding unnecessary files from gitignore - Given this step says to skip - And I have a "a/b/c/test.txt" file with content: + Scenario: Excluding unnecessary files from .gitignore + Given I have a "a/b/c/test.txt" file with content: """ ~~ @todo #44 some puzzle to be excluded """ And I have a "f/g/h/hello.md" file with content: """ - ~~ @todo #44 some puzzle to be excluded as well + ~~ @todo #45 some puzzle to be excluded as well """ And I have a ".gitignore" file with content: """ @@ -80,10 +79,52 @@ Feature: Command Line Processing a/**/* !/f """ - When I run bin/pdd with "> out.xml" + When I run bin/pdd with "--skip-gitignore > out.xml" + Then Exit code is zero + And XML file "out.xml" matches "/puzzles/puzzle[./ticket='45']" + And XML file "out.xml" matches "/puzzles[count(puzzle)=1]" + + Scenario: Excluding unnecessary files from .gitignore and ignore comments + Given I have a "a/b/c/test.txt" file with content: + """ + ~~ @todo #44 some puzzle to be excluded + """ + And I have a "f/g/h/hello.md" file with content: + """ + ~~ @todo #45 some puzzle to be excluded as well + """ + And I have a ".gitignore" file with content: + """ + # This is the list of patterns + # a/**/* + f/**/* + """ + When I run bin/pdd with "--skip-gitignore > out.xml" Then Exit code is zero + And XML file "out.xml" matches "/puzzles/puzzle[./ticket='44']" And XML file "out.xml" matches "/puzzles[count(puzzle)=1]" + Scenario: Files from .gitignore is not excluded by default + Given I have a "a/b/c/test.txt" file with content: + """ + ~~ @todo #44 some puzzle to be excluded + """ + And I have a "f/g/h/hello.md" file with content: + """ + ~~ @todo #45 some puzzle to be excluded as well + """ + And I have a ".gitignore" file with content: + """ + # This is the list of patterns + a/**/* + !/f + """ + When I run bin/pdd with "> out.xml" + Then Exit code is zero + And XML file "out.xml" matches "/puzzles/puzzle[./ticket='44']" + And XML file "out.xml" matches "/puzzles/puzzle[./ticket='45']" + And XML file "out.xml" matches "/puzzles[count(puzzle)=2]" + Scenario: Rejects unknown options Given I have a "test.txt" file with content: """ diff --git a/features/step_definitions/steps.rb b/features/step_definitions/steps.rb index fd44afc..4304cae 100644 --- a/features/step_definitions/steps.rb +++ b/features/step_definitions/steps.rb @@ -41,7 +41,7 @@ FileUtils.rm_rf(@dir) end -Given(/skip/) do +Given(/skip test/) do skip_this_scenario end