From e3eb1b90c50d56d9958724cde3d9c1410fd22a8b Mon Sep 17 00:00:00 2001 From: Adam Roben Date: Thu, 18 Dec 2014 11:00:57 -0500 Subject: [PATCH] Test that grammars.yml agrees with the list of submodules If any submodules are missing from grammars.yml, or are listed in grammars.yml but missing from the repo, the test will fail. Eventually it would be good to test that the scopes for each submodule are accurate, but that will take some more work. --- test/test_grammars.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/test/test_grammars.rb b/test/test_grammars.rb index 96fdb667..0bbd8923 100644 --- a/test/test_grammars.rb +++ b/test/test_grammars.rb @@ -1,8 +1,10 @@ require_relative "./helper" class TestGrammars < Test::Unit::TestCase + ROOT = File.expand_path("../..", __FILE__) + def setup - @grammars = YAML.load(File.read(File.expand_path("../../grammars.yml", __FILE__))) + @grammars = YAML.load(File.read(File.join(ROOT, "grammars.yml"))) end def test_no_duplicate_scopes @@ -10,4 +12,26 @@ class TestGrammars < Test::Unit::TestCase duplicates = scopes.group_by { |s| s }.select { |k, v| v.length > 1 }.map(&:first) assert duplicates.empty?, "The following scopes appear in grammars.yml more than once:\n#{duplicates.sort.join("\n")}" end + + def test_submodules_are_in_sync + submodules = `git config --list --file "#{File.join(ROOT, ".gitmodules")}"`.lines.grep(/\.path=/).map { |line| line.chomp.split("=", 2).last } + # Strip off paths inside the submodule so that just the submodule path remains. + listed_submodules = @grammars.keys.grep(/grammar_sources/).map { |source| source[%r{grammar_sources/[^/]+}] } + + nonexistent_submodules = listed_submodules - submodules + unlisted_submodules = submodules - listed_submodules + + message = "" + unless nonexistent_submodules.empty? + message << "The following submodules are listed in grammars.yml but don't seem to exist in the repository. Maybe you should remove them from grammars.yml?\n" + message << nonexistent_submodules.sort.join("\n") + end + unless unlisted_submodules.empty? + message << "\n" unless message.empty? + message << "The following submodules exist in the repository but aren't listed in grammars.yml. Maybe you should add them to grammars.yml?\n" + message << unlisted_submodules.sort.join("\n") + end + + assert nonexistent_submodules.empty? && unlisted_submodules.empty?, message + end end