Skip to content

Commit

Permalink
add spec/search/texdocs_spec; refactor alias_spec.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
wtsnjp committed Aug 12, 2024
1 parent aca8b4d commit add562e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 14 deletions.
32 changes: 19 additions & 13 deletions spec/search/alias_spec.rb
Original file line number Diff line number Diff line change
@@ -1,40 +1,46 @@
require 'spec_helper'
require 'digest/md5'

RSpec.describe "Alias", :type => :aruba do
include_context "messages"
include_context "texmf"

let(:texdoc_cnf) { texmf_home / "texdoc/texdoc.cnf" }
let(:test_texdoc_cnf) { texmf_home / "texdoc/texdoc.cnf" }

context "is set in texdoc.cnf" do
let(:config_content) {
<<~EOF
alias testalias = texlive
EOF
}
before(:each) { File.write(texdoc_cnf, config_content) }
let(:realpath) { Regexp.escape(normalize_path("texlive/texlive-en/texlive-en.pdf")) }
before(:each) { File.write(test_texdoc_cnf, config_content) }

let(:test_res_name) { "texlive/texlive-en/texlive-en.pdf" }
let(:test_res_hash) { Digest::MD5.hexdigest(test_res_name)[0, 7] }
let(:test_res_realpath) { Regexp.escape(normalize_path(test_res_name)) }

context "and query the exact alias" do
before(:each) { run_texdoc "-ddocfile", "testalias" }
let(:test_query) { "testalias" }
before(:each) { run_texdoc "-ddocfile", test_query }

it "should find aliased documents" do
expect(stderr).to include(debug_line "search", 'Searching documents for pattern "testalias"')
expect(stderr).to match(/texdoc debug-search: \(0da8ec4\) File \S*#{realpath} found/)
expect(stderr).to include(debug_line "docfile", "(0da8ec4) name: texlive/texlive-en/texlive-en.pdf")
expect(stderr).to include(debug_line "docfile", "(0da8ec4) matches: texlive (alias)")
expect(stderr).to include(debug_line "search", "Searching documents for pattern \"#{test_query}\"")
expect(stderr).to match(/#{debug_line "search"} \(#{test_res_hash}\) File \S*#{test_res_realpath} found/)
expect(stderr).to include(debug_line "docfile", "(#{test_res_hash}) name: #{test_res_name}")
expect(stderr).to include(debug_line "docfile", "(#{test_res_hash}) matches: texlive (alias)")
expect(last_command_started).to be_successfully_executed
end
end

context "and query a misspelled alias" do
before(:each) { run_texdoc "-M", "-ddocfile", "testaliases" }
let(:test_query) { "testaliases" }
before(:each) { run_texdoc "-M", "-ddocfile", test_query }

it "should not find aliased documents" do
expect(stderr).to include(debug_line "search", 'Searching documents for pattern "testaliases"')
expect(stderr).not_to match(/texdoc debug-search: \(0da8ec4\) File \S*#{realpath} found/)
expect(stderr).not_to include(debug_line "docfile", "(0da8ec4) name: texlive/texlive-en/texlive-en.pdf")
expect(stderr).not_to include(debug_line "docfile", "(0da8ec4) matches: texlive (alias)")
expect(stderr).to include(debug_line "search", "Searching documents for pattern \"#{test_query}\"")
expect(stderr).not_to match(/#{debug_line "search"} \(#{test_res_hash}\) File \S*#{test_res_realpath} found/)
expect(stderr).not_to include(debug_line "docfile", "(#{test_res_hash}) name: #{test_res_name}")
expect(stderr).not_to include(debug_line "docfile", "(#{test_res_hash}) matches: texlive (alias)")
end
end
end
Expand Down
24 changes: 23 additions & 1 deletion spec/search/texdocs_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'
require 'digest/md5'

RSpec.describe "TEXDOCS handling", :type => :aruba do
RSpec.describe "Handling texdocs", :type => :aruba do
include_context "messages"
include_context "texmf"

Expand Down Expand Up @@ -55,3 +56,24 @@
end
end
end

RSpec.describe "Document search in texdocs", :type => :aruba do
include_context "messages"

context "for a docfile name query" do
let(:test_res_name) { "latex/babel/babel-code.pdf" }
let(:test_res_hash) { Digest::MD5.hexdigest(test_res_name)[0, 7] }
let(:test_res_realpath) { Regexp.escape(normalize_path(test_res_name)) }

let(:test_query) { "babel-code" }
before(:each) { run_texdoc "-ddocfile", test_query }

it "should find the documents" do
expect(stderr).to include(debug_line "search", "Searching documents for pattern \"#{test_query}\"")
expect(stderr).to match(/#{debug_line "search"} \(#{test_res_hash}\) File \S*#{test_res_realpath} found/)
expect(stderr).to include(debug_line "docfile", "(#{test_res_hash}) name: #{test_res_name}")
expect(stderr).to include(debug_line "docfile", "(#{test_res_hash}) matches: #{test_query}")
expect(stderr).to include(debug_line "docfile", "(#{test_res_hash}) source: texdocs")
end
end
end

0 comments on commit add562e

Please sign in to comment.