Skip to content

Commit

Permalink
Fix include using symbol (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
noteflakes committed Jan 22, 2018
1 parent 067cece commit 1b68559
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/lyp/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,17 @@ def find_include_file(ref, dir, location)
search_paths = [dir]
search_paths += @opts[:include_paths] if @opts[:include_paths]

# Reminder: return inside a proc returns from the caller
search = proc {|fn| return fn if File.file?(fn) }

search_paths.each do |path|
full_path = File.expand_path(ref, path)
return full_path if File.file?(full_path)
search.(full_path)
search.("#{full_path}.ily")
search.("#{full_path}.ly")
end

error("Missing include file specified in %s", location)
error("Could not find include file reference #{ref} specified in %s", location)
end

def process_require_command(ref, dir, leaf, opts, location)
Expand Down
6 changes: 5 additions & 1 deletion spec/resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,11 @@ def resolver(tree = Lyp::DependencyLeaf.new, opts = {})

it "supports require with symbol instead of string" do
with_packages(:simple) do
resolver = resolver('spec/user_files/simple_symbol.ly')
# resolver = resolver('spec/user_files/simple_symbol.ly')
# o = resolver.compile_dependency_tree
# expect(o.dependencies.keys).to eq(%w{a c})

resolver = resolver('spec/user_files/include_symbol.ly')
o = resolver.compile_dependency_tree
expect(o.dependencies.keys).to eq(%w{a c})
end
Expand Down
15 changes: 14 additions & 1 deletion spec/the_works_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@
end
end

it "installs lilypond+package and compiles successfully with symbols" do
with_lilyponds(:empty) do
with_packages(:tmp) do
Lyp::Lilypond.install('2.19.35', silent: true)
Lyp::Package.install('dummy', silent: true)

Lyp::Lilypond.compile(["#{$spec_dir}/user_files/the-works-symbols.ly"])

output = "#{$_out}\n#{$_err}"
expect(output).to match(/Hello from package/)
end
end
end

it "correctly sets global lyp variables" do
with_lilyponds(:empty) do
with_packages(:test_vars) do
Expand All @@ -29,7 +43,6 @@
expect(output).to include("input-dirname: #{File.dirname(user_file)}")
expect(output).to include("current-package-dir: #{$packages_dir}/b@0.2")
expect(output).to include("bvar: hello from b/inc/include1.ly")

end
end
end
Expand Down
1 change: 1 addition & 0 deletions spec/user_files/include_symbol.ly
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
\pinclude simple_symbol

0 comments on commit 1b68559

Please sign in to comment.