diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2021-11-01 23:52:50 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-11-01 23:52:50 -0600 |
| commit | f375d179a528f8c3450c44c8f040892fbe70463b (patch) | |
| tree | d5004ed0ed75146d63d2d578807a12c46473afb3 /test | |
| parent | aa4227c5b273182e3267f7fb63aa486575de83f8 (diff) | |
resolves #3868 add --log-level option to CLI to control log level (PR #4198)
Diffstat (limited to 'test')
| -rw-r--r-- | test/invoker_test.rb | 48 | ||||
| -rw-r--r-- | test/options_test.rb | 12 |
2 files changed, 60 insertions, 0 deletions
diff --git a/test/invoker_test.rb b/test/invoker_test.rb index 4f9832b4..43fb48cf 100644 --- a/test/invoker_test.rb +++ b/test/invoker_test.rb @@ -163,6 +163,54 @@ context 'Invoker' do assert_match(/WARNING/, warnings) end + test 'should change level on logger when --log-level is specified' do + input = <<~'EOS' + skip to <<install>> + + . download + . install[[install]] + . run + EOS + output = nil + redirect_streams do |_, err| + invoke_cli(%w(--log-level info), '-') { input } + output = err.string + end + assert_equal 'asciidoctor: INFO: possible invalid reference: install', output.chomp + end + + test 'should not log when --log-level and -q are both specified' do + input = <<~'EOS' + skip to <<install>> + + . download + . install[[install]] + . run + EOS + output = nil + redirect_streams do |_, err| + invoke_cli(%w(--log-level info -q), '-') { input } + output = err.string + end + assert_empty output + end + + test 'should use specified log level when --log-level and -v are both specified' do + input = <<~'EOS' + skip to <<install>> + + . download + . install[[install]] + . run + EOS + output = nil + redirect_streams do |_, err| + invoke_cli(%w(--log-level warn -v), '-') { input } + output = err.string + end + assert_empty output + end + test 'should enable script warnings if -w flag is specified' do old_verbose, $VERBOSE = $VERBOSE, false begin diff --git a/test/options_test.rb b/test/options_test.rb index c57e43c0..636b0f6b 100644 --- a/test/options_test.rb +++ b/test/options_test.rb @@ -271,6 +271,18 @@ context 'Options' do assert_includes messages, 'invalid argument: --failure-level=foobar' end + test 'should set log level to DEBUG when --log-level option is specified' do + options = Asciidoctor::Cli::Options.parse! %w(--log-level debug test/fixtures/sample.adoc) + assert_equal Logger::Severity::DEBUG, options[:log_level] + end + + test 'should allow log level to be set to WARN using any recognized abbreviation' do + %w(w warn WARN warning WARNING).each do |val| + options = Asciidoctor::Cli::Options.parse! %W(--log-level=#{val} test/fixtures/sample.adoc) + assert_equal ::Logger::Severity::WARN, options[:log_level] + end + end + test 'should set verbose to 2 when -v flag is specified' do options = Asciidoctor::Cli::Options.parse! %w(-v test/fixtures/sample.adoc) assert_equal 2, options[:verbose] |
