Fix header_generator_test (#88)

* Fix header_generator_test

Due to a missing `unittest.main()` call, the header_generator_test was
not actually running any tests when run with bazel/run directly.
However, the failure was noticed by `python -m unittest discover`. Fixed
the header_generator_test in the following ways:

 - Import test_util (tests failed due to missing import).
 - Change attribute_checker.normalize_and_verify to
   header_generator.generate_header.
 - Remove unused imports.
 - Make appropriate BUILD changes.
 - Add unittest.main() call so that unit tests are run.

Additionally, this change adds a (blank) __init__.py to compiler/ and
compiler/util/ so that they are importable by the unittest module. This
means that running `python -m unittest discover -p '*_test.py'` from the
main emboss repository should run all python tests in the compiler - and
could be a good sanity check to make sure all python tests pass, even
when `bazel test compiler/...` could miss tests (not declared in BUILD
or missing the unittest.main() call).

* Move front_end/test_util to util/test_util
diff --git a/compiler/__init__.py b/compiler/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/compiler/__init__.py
diff --git a/compiler/back_end/cpp/BUILD b/compiler/back_end/cpp/BUILD
index 2280c36..c67b686 100644
--- a/compiler/back_end/cpp/BUILD
+++ b/compiler/back_end/cpp/BUILD
@@ -55,6 +55,7 @@
     deps = [
         ":header_generator",
         "//compiler/front_end:glue",
+        "//compiler/util:test_util",
     ],
 )
 
diff --git a/compiler/back_end/cpp/header_generator_test.py b/compiler/back_end/cpp/header_generator_test.py
index e057c0d..f20c1ae 100644
--- a/compiler/back_end/cpp/header_generator_test.py
+++ b/compiler/back_end/cpp/header_generator_test.py
@@ -18,8 +18,7 @@
 from compiler.back_end.cpp import header_generator
 from compiler.front_end import glue
 from compiler.util import error
-from compiler.util import ir_pb2
-from compiler.util import ir_util
+from compiler.util import test_util
 
 
 def _make_ir_from_emb(emb_text, name="m.emb"):
@@ -50,4 +49,8 @@
     self.assertEqual([[
         error.error("m.emb", attr.name.source_location,
                     "Unknown attribute '(cpp) byte_order' on module 'm.emb'.")
-    ]], attribute_checker.normalize_and_verify(ir))
+    ]], header_generator.generate_header(ir)[1])
+
+
+if __name__ == "__main__":
+    unittest.main()
diff --git a/compiler/front_end/BUILD b/compiler/front_end/BUILD
index f8d8484..024524d 100644
--- a/compiler/front_end/BUILD
+++ b/compiler/front_end/BUILD
@@ -82,9 +82,9 @@
     deps = [
         ":module_ir",
         ":parser",
-        ":test_util",
         ":tokenizer",
         "//compiler/util:ir_pb2",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -115,25 +115,6 @@
 )
 
 py_library(
-    name = "test_util",
-    testonly = 1,
-    srcs = ["test_util.py"],
-    deps = [
-    ],
-)
-
-py_test(
-    name = "test_util_test",
-    srcs = ["test_util_test.py"],
-    python_version = "PY3",
-    deps = [
-        ":test_util",
-        "//compiler/util:ir_pb2",
-        "//compiler/util:parser_types",
-    ],
-)
-
-py_library(
     name = "glue",
     srcs = ["glue.py"],
     data = [
@@ -168,10 +149,10 @@
     python_version = "PY3",
     deps = [
         ":glue",
-        ":test_util",
         "//compiler/util:ir_pb2",
         "//compiler/util:error",
         "//compiler/util:parser_types",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -193,7 +174,7 @@
     deps = [
         ":glue",
         ":synthetics",
-        ":test_util",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -216,8 +197,8 @@
     deps = [
         ":glue",
         ":symbol_resolver",
-        ":test_util",
         "//compiler/util:error",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -240,9 +221,9 @@
     python_version = "PY3",
     deps = [
         ":glue",
-        ":test_util",
         ":write_inference",
         "//compiler/util:ir_pb2",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -274,10 +255,10 @@
     deps = [
         ":attribute_checker",
         ":glue",
-        ":test_util",
         "//compiler/util:ir_pb2",
         "//compiler/util:error",
         "//compiler/util:ir_util",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -299,9 +280,9 @@
     python_version = "PY3",
     deps = [
         ":glue",
-        ":test_util",
         ":type_check",
         "//compiler/util:error",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -326,7 +307,7 @@
     deps = [
         ":expression_bounds",
         ":glue",
-        ":test_util",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -352,8 +333,8 @@
     deps = [
         ":constraints",
         ":glue",
-        ":test_util",
         "//compiler/util:error",
+        "//compiler/util:test_util",
     ],
 )
 
@@ -375,8 +356,8 @@
     deps = [
         ":dependency_checker",
         ":glue",
-        ":test_util",
         "//compiler/util:error",
+        "//compiler/util:test_util",
     ],
 )
 
diff --git a/compiler/front_end/attribute_checker_test.py b/compiler/front_end/attribute_checker_test.py
index bb57ac9..11a5c18 100644
--- a/compiler/front_end/attribute_checker_test.py
+++ b/compiler/front_end/attribute_checker_test.py
@@ -17,10 +17,10 @@
 import unittest
 from compiler.front_end import attribute_checker
 from compiler.front_end import glue
-from compiler.front_end import test_util
 from compiler.util import error
 from compiler.util import ir_pb2
 from compiler.util import ir_util
+from compiler.util import test_util
 
 # These are not shared with attribute_checker.py because their values are part
 # of the contract with back ends.
diff --git a/compiler/front_end/constraints_test.py b/compiler/front_end/constraints_test.py
index 9bf5a8e..b214107 100644
--- a/compiler/front_end/constraints_test.py
+++ b/compiler/front_end/constraints_test.py
@@ -18,9 +18,9 @@
 from compiler.front_end import attributes
 from compiler.front_end import constraints
 from compiler.front_end import glue
-from compiler.front_end import test_util
 from compiler.util import error
 from compiler.util import ir_util
+from compiler.util import test_util
 
 
 def _make_ir_from_emb(emb_text, name="m.emb"):
diff --git a/compiler/front_end/dependency_checker_test.py b/compiler/front_end/dependency_checker_test.py
index ba7ceb7..27af812 100644
--- a/compiler/front_end/dependency_checker_test.py
+++ b/compiler/front_end/dependency_checker_test.py
@@ -17,8 +17,8 @@
 import unittest
 from compiler.front_end import dependency_checker
 from compiler.front_end import glue
-from compiler.front_end import test_util
 from compiler.util import error
+from compiler.util import test_util
 
 
 def _parse_snippet(emb_file):
diff --git a/compiler/front_end/expression_bounds_test.py b/compiler/front_end/expression_bounds_test.py
index 15870b4..54fa0ce 100644
--- a/compiler/front_end/expression_bounds_test.py
+++ b/compiler/front_end/expression_bounds_test.py
@@ -17,7 +17,7 @@
 import unittest
 from compiler.front_end import expression_bounds
 from compiler.front_end import glue
-from compiler.front_end import test_util
+from compiler.util import test_util
 
 
 class ComputeConstantsTest(unittest.TestCase):
diff --git a/compiler/front_end/glue_test.py b/compiler/front_end/glue_test.py
index cc8469c..5c7308b 100644
--- a/compiler/front_end/glue_test.py
+++ b/compiler/front_end/glue_test.py
@@ -18,10 +18,10 @@
 import unittest
 
 from compiler.front_end import glue
-from compiler.front_end import test_util
 from compiler.util import error
 from compiler.util import ir_pb2
 from compiler.util import parser_types
+from compiler.util import test_util
 
 _location = parser_types.make_location
 
diff --git a/compiler/front_end/module_ir_test.py b/compiler/front_end/module_ir_test.py
index b4451ef..b2ad69b 100644
--- a/compiler/front_end/module_ir_test.py
+++ b/compiler/front_end/module_ir_test.py
@@ -22,9 +22,9 @@
 
 from compiler.front_end import module_ir
 from compiler.front_end import parser
-from compiler.front_end import test_util
 from compiler.front_end import tokenizer
 from compiler.util import ir_pb2
+from compiler.util import test_util
 
 _TESTDATA_PATH = "testdata.golden"
 _MINIMAL_SOURCE = pkgutil.get_data(
diff --git a/compiler/front_end/symbol_resolver_test.py b/compiler/front_end/symbol_resolver_test.py
index 4428f26..deaf1a0 100644
--- a/compiler/front_end/symbol_resolver_test.py
+++ b/compiler/front_end/symbol_resolver_test.py
@@ -17,8 +17,8 @@
 import unittest
 from compiler.front_end import glue
 from compiler.front_end import symbol_resolver
-from compiler.front_end import test_util
 from compiler.util import error
+from compiler.util import test_util
 
 _HAPPY_EMB = """
 struct Foo:
diff --git a/compiler/front_end/synthetics_test.py b/compiler/front_end/synthetics_test.py
index 904b6cf..ceafa11 100644
--- a/compiler/front_end/synthetics_test.py
+++ b/compiler/front_end/synthetics_test.py
@@ -17,9 +17,9 @@
 import unittest
 from compiler.front_end import glue
 from compiler.front_end import synthetics
-from compiler.front_end import test_util
 from compiler.util import error
 from compiler.util import ir_pb2
+from compiler.util import test_util
 
 
 class SyntheticsTest(unittest.TestCase):
diff --git a/compiler/front_end/type_check_test.py b/compiler/front_end/type_check_test.py
index c5f174f..6906738 100644
--- a/compiler/front_end/type_check_test.py
+++ b/compiler/front_end/type_check_test.py
@@ -16,9 +16,9 @@
 
 import unittest
 from compiler.front_end import glue
-from compiler.front_end import test_util
 from compiler.front_end import type_check
 from compiler.util import error
+from compiler.util import test_util
 
 
 class TypeAnnotationTest(unittest.TestCase):
diff --git a/compiler/front_end/write_inference_test.py b/compiler/front_end/write_inference_test.py
index 0928d94..52e8c26 100644
--- a/compiler/front_end/write_inference_test.py
+++ b/compiler/front_end/write_inference_test.py
@@ -16,9 +16,9 @@
 
 import unittest
 from compiler.front_end import glue
-from compiler.front_end import test_util
 from compiler.front_end import write_inference
 from compiler.util import ir_pb2
+from compiler.util import test_util
 
 
 class WriteInferenceTest(unittest.TestCase):
diff --git a/compiler/util/BUILD b/compiler/util/BUILD
index c9ec128..4c34cc1 100644
--- a/compiler/util/BUILD
+++ b/compiler/util/BUILD
@@ -79,6 +79,24 @@
 )
 
 py_library(
+    name = "test_util",
+    testonly = 1,
+    srcs = ["test_util.py"],
+    deps = [],
+)
+
+py_test(
+    name = "test_util_test",
+    srcs = ["test_util_test.py"],
+    python_version = "PY3",
+    deps = [
+        ":test_util",
+        "//compiler/util:ir_pb2",
+        "//compiler/util:parser_types",
+    ],
+)
+
+py_library(
     name = "traverse_ir",
     srcs = ["traverse_ir.py"],
     deps = [
diff --git a/compiler/util/__init__.py b/compiler/util/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/compiler/util/__init__.py
diff --git a/compiler/front_end/test_util.py b/compiler/util/test_util.py
similarity index 100%
rename from compiler/front_end/test_util.py
rename to compiler/util/test_util.py
diff --git a/compiler/front_end/test_util_test.py b/compiler/util/test_util_test.py
similarity index 99%
rename from compiler/front_end/test_util_test.py
rename to compiler/util/test_util_test.py
index c5ba61b..a0512aa 100644
--- a/compiler/front_end/test_util_test.py
+++ b/compiler/util/test_util_test.py
@@ -16,9 +16,9 @@
 
 import unittest
 
-from compiler.front_end import test_util
 from compiler.util import ir_pb2
 from compiler.util import parser_types
+from compiler.util import test_util
 
 
 class ProtoIsSupersetTest(unittest.TestCase):