Skip to content

Commit

Permalink
refactor shared context "texmf_context"
Browse files Browse the repository at this point in the history
  • Loading branch information
wtsnjp committed Aug 13, 2024
1 parent d38a520 commit c09bb59
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 35 deletions.
14 changes: 7 additions & 7 deletions spec/action/files_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@

context "the output" do
# known files
let(:texdoclib) { texmf_home / "scripts/texdoc/texdoclib.tlu" }
let(:texdoclib) { ps_texmf_home / "scripts/texdoc/texdoclib.tlu" }

let(:dist_texdoc_dist_cnf) { texmf_dist / "texdoc/texdoc-dist.cnf" }
let(:dist_texdoc_cnf) { texmf_dist / "texdoc/texdoc.cnf" }
let(:dist_texdoc_dist_cnf) { ps_texmf_dist / "texdoc/texdoc-dist.cnf" }
let(:dist_texdoc_cnf) { ps_texmf_dist / "texdoc/texdoc.cnf" }

let(:home_texdoc_dist_cnf) { texmf_home / "texdoc/texdoc-dist.cnf" }
let(:home_texdoc_cnf) { texmf_home / "texdoc/texdoc.cnf" }
let(:home_texdoc_dist_cnf) { ps_texmf_home / "texdoc/texdoc-dist.cnf" }
let(:home_texdoc_cnf) { ps_texmf_home / "texdoc/texdoc.cnf" }

# message
let(:version_info) { "#{normalize_path(texdoclib)} #{version}" }
Expand All @@ -51,7 +51,7 @@ def file_line status, file
end

context "with normal setting" do
before(:each) { set_environment_variable "TEXMFDIST", texmf_dist.to_s }
before(:each) { set_environment_variable "TEXMFDIST", ps_texmf_dist.to_s }
before(:each) { run_texdoc "-f" }

it "should contain version information" do
Expand All @@ -78,7 +78,7 @@ def file_line status, file
end

context "with verbose setting" do
before(:each) { set_environment_variable "TEXMFDIST", texmf_dist.to_s }
before(:each) { set_environment_variable "TEXMFDIST", ps_texmf_dist.to_s }
before(:each) { run_texdoc "-vf" }

it "should contain version information" do
Expand Down
7 changes: 2 additions & 5 deletions spec/config/items_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

context "texlive_tlpdb" do
context "to set custom path" do
before(:each) { set_environment_variable "TEXMFVAR", texmf_var.to_s }
before(:each) {
run_texdoc "-dtlpdb", "-c texlive_tlpdb=#{tlpdb.to_s}", "texlive-en"
run_texdoc "-dtlpdb", "-c texlive_tlpdb=#{ps_tlpdb.to_s}", "texlive-en"
}

after(:each) { FileUtils.remove_dir(texmf_var) }

it "should be effective" do
expect(stderr).to include(
debug_line "tlpdb", "Getting data from tlpdb file #{tlpdb.to_s}")
debug_line "tlpdb", "Getting data from tlpdb file #{ps_tlpdb.to_s}")
end
end

Expand Down
2 changes: 0 additions & 2 deletions spec/config/texdoc_cnf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
include_context "messages"
include_context "texmf"

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

context "config lines in texdoc.cnf" do
let(:config_content) {
<<~EOF
Expand Down
2 changes: 0 additions & 2 deletions spec/config/texdoc_dist_cnf_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
include_context "messages"
include_context "texmf"

let(:texdoc_cnf) { texmf_home / "texdoc/texdoc.cnf" }
let(:texdoc_dist_cnf) { texmf_home / "texdoc/texdoc-dist.cnf" }

context "when it loaded" do
before(:each) { run_texdoc "-dconfig", "-lI", "texlive-en" }
Expand Down
2 changes: 0 additions & 2 deletions spec/score/adjscore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
include_context "messages"
include_context "texmf"

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

context "global pattern score adjustment" do
let(:config_content) {
<<~EOF
Expand Down
4 changes: 1 addition & 3 deletions spec/search/alias_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
include_context "messages"
include_context "texmf"

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(test_texdoc_cnf, config_content) }
before(:each) { File.write(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] }
Expand Down
4 changes: 2 additions & 2 deletions spec/search/texdocs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
context "with standard testing setup" do
before(:each) { run_texdoc "-dtexdocs", "listings" }

let(:texmf_dist_regex) { Regexp.escape(normalize_path(`kpsewhich -var-value TEXMFDIST`.chomp)) }
let(:texmf_home_regex) { Regexp.escape(normalize_path(texmf_home)) }
let(:texmf_dist_regex) { Regexp.escape(normalize_path(texmf_dist)) }
let(:texmf_home_regex) { Regexp.escape(normalize_path(ps_texmf_home)) }

let(:path_doc_suffix_regex) { Regexp.escape(normalize_path("/doc")) }
let(:shift_doc_suffix_regex) { Regexp.escape(normalize_path("doc/")) }
Expand Down
12 changes: 6 additions & 6 deletions spec/support/helpers/texdoc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ module Texdoc

TMP_DIR = BASE_DIR / "tmp"

REPO_TEXMF = TMP_DIR / "texmf"
REPO_TEXMF_HOME = TMP_DIR / "texmf"
REPO_TEXMF_DIST = TMP_DIR / "texmf-dist"
REPO_TEXLIVE_TLPDB = TMP_DIR / "texlive.tlpdb"
REPO_TEXLIVE_TLPDB = TMP_DIR / "texlive.tlpdb" # used in shared_context/texmf_context.rb

# for testing
HOME_DIR = TMP_DIR / "aruba"

PS_TEXMF = HOME_DIR / "texmf"
PS_TEXMF_DIST = HOME_DIR / "texmf-dist"
PS_TEXMF_HOME = HOME_DIR / "texmf"
PS_TEXMF_DIST = HOME_DIR / "texmf-dist" # used in shared_context/texmf_context.rb
PS_TEXMF_VAR = HOME_DIR / "texmf-var"

# mock
Expand All @@ -38,10 +38,10 @@ def setup_mock_viewers

# setup TEXMF trees
def setup_texmf_trees
FileUtils.cp_r(REPO_TEXMF, HOME_DIR)
FileUtils.cp_r(REPO_TEXMF_HOME, HOME_DIR)
FileUtils.cp_r(REPO_TEXMF_DIST, HOME_DIR)

set_environment_variable "TEXMFHOME", PS_TEXMF.to_s
set_environment_variable "TEXMFHOME", PS_TEXMF_HOME.to_s
set_environment_variable "TEXMFVAR", PS_TEXMF_VAR.to_s
# WARNING: leave TEXMFDIST as is for searching local TeX Live docs
end
Expand Down
18 changes: 12 additions & 6 deletions spec/support/shared_contexts/texmf_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@
require 'pathname'

shared_context "texmf" do
# pseudo TEXMF trees
let(:texmf_home) { SpecHelplers::Texdoc::PS_TEXMF }
let(:texmf_dist) { SpecHelplers::Texdoc::PS_TEXMF_DIST }
let(:texmf_var) { SpecHelplers::Texdoc::PS_TEXMF_VAR }
# pseudo TEXMF trees (dynamically generated)
let(:ps_texmf_home) { SpecHelplers::Texdoc::PS_TEXMF_HOME }
let(:ps_texmf_dist) { SpecHelplers::Texdoc::PS_TEXMF_DIST }

# the only real TEXMF tree
let(:texmf_dist) { `kpsewhich --var-value TEXMFDIST`.chomp }

# link to texlive.tlpdb
let(:tlpdb) { SpecHelplers::Texdoc::REPO_TEXLIVE_TLPDB }
let(:ps_tlpdb) { SpecHelplers::Texdoc::REPO_TEXLIVE_TLPDB }

# texdoc.cnf for testing
let(:texdoc_cnf) { ps_texmf_home / "texdoc/texdoc.cnf" }
let(:texdoc_dist_cnf) { ps_texmf_home / "texdoc/texdoc-dist.cnf" }

# sample files
["html", "htm", "dvi", "md", "txt", "pdf", "ps", "tex"].each do |ext|
let("sample_#{ext}".to_sym) {
texmf_home / "doc/sample/sample.#{ext}"
ps_texmf_home / "doc/sample/sample.#{ext}"
}
end
end

0 comments on commit c09bb59

Please sign in to comment.