diff --git a/lib/lyp/resolver.rb b/lib/lyp/resolver.rb index f88a76a..f72e7f6 100644 --- a/lib/lyp/resolver.rb +++ b/lib/lyp/resolver.rb @@ -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) diff --git a/spec/resolver_spec.rb b/spec/resolver_spec.rb index 6d4e35f..2c9efc3 100644 --- a/spec/resolver_spec.rb +++ b/spec/resolver_spec.rb @@ -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 diff --git a/spec/the_works_spec.rb b/spec/the_works_spec.rb index 79b6a59..58b99e0 100644 --- a/spec/the_works_spec.rb +++ b/spec/the_works_spec.rb @@ -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 @@ -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 diff --git a/spec/user_files/include_symbol.ly b/spec/user_files/include_symbol.ly new file mode 100644 index 0000000..cc3a8af --- /dev/null +++ b/spec/user_files/include_symbol.ly @@ -0,0 +1 @@ +\pinclude simple_symbol