From b88fcdd0db5785b2cb69357098db1bd612c1590c Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Thu, 30 Aug 2012 01:20:56 +0200
Subject: [PATCH] Remove QC.hs and replace it with an auto-generated file

In order to have correct code coverage results, we must somehow import
all production modules into the test runner. Until now, this was done
manually (when we didn't forget) in QC.hs.

To improve the situation, we remove QC.hs and replace it with an
auto-generated file which imports all modules. This reduces the
maintenance burden and ensures we'll always have correct coverage.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Michael Hanselmann <hansmi@google.com>
---
 .gitignore                          |   1 +
 Makefile.am                         |  19 +++++-
 htest/Test/Ganeti/TestImports.hs.in |   7 ++
 htest/test.hs                       |   2 +-
 htools/Ganeti/HTools/QC.hs          | 100 ----------------------------
 5 files changed, 25 insertions(+), 104 deletions(-)
 create mode 100644 htest/Test/Ganeti/TestImports.hs.in
 delete mode 100644 htools/Ganeti/HTools/QC.hs

diff --git a/.gitignore b/.gitignore
index 66f5ed1a3..3097b498f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -123,3 +123,4 @@
 
 /htools/Ganeti/HTools/Version.hs
 /htools/Ganeti/Constants.hs
+/htest/Test/Ganeti/TestImports.hs
diff --git a/Makefile.am b/Makefile.am
index eab7f56ec..e7bc30917 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -382,6 +382,7 @@ HPCEXCL = --exclude Main \
 	--exclude Test.Ganeti.TestCommon \
 	--exclude Test.Ganeti.TestHTools \
 	--exclude Test.Ganeti.TestHelper \
+	--exclude Test.Ganeti.TestImports \
 	$(patsubst htools.%,--exclude Test.%,$(subst /,.,$(patsubst %.hs,%, $(HS_LIB_SRCS))))
 
 HS_LIB_SRCS = \
@@ -396,7 +397,6 @@ HS_LIB_SRCS = \
 	htools/Ganeti/HTools/Luxi.hs \
 	htools/Ganeti/HTools/Node.hs \
 	htools/Ganeti/HTools/PeerMap.hs \
-	htools/Ganeti/HTools/QC.hs \
 	htools/Ganeti/HTools/Rapi.hs \
 	htools/Ganeti/HTools/Simu.hs \
 	htools/Ganeti/HTools/Text.hs \
@@ -462,7 +462,10 @@ HS_TEST_SRCS = \
 
 HS_LIBTEST_SRCS = $(HS_LIB_SRCS) $(HS_TEST_SRCS)
 
-HS_BUILT_SRCS = htools/Ganeti/HTools/Version.hs htools/Ganeti/Constants.hs
+HS_BUILT_SRCS = \
+	htest/Test/Ganeti/TestImports.hs \
+	htools/Ganeti/Constants.hs \
+	htools/Ganeti/HTools/Version.hs
 HS_BUILT_SRCS_IN = $(patsubst %,%.in,$(HS_BUILT_SRCS))
 
 $(RUN_IN_TEMPDIR): | stamp-directories
@@ -1114,6 +1117,16 @@ htools/Ganeti/Constants.hs: htools/Ganeti/Constants.hs.in \
 	set -e; \
 	{ cat $< ; PYTHONPATH=. $(CONVERT_CONSTANTS); } > $@
 
+htest/Test/Ganeti/TestImports.hs: htest/Test/Ganeti/TestImports.hs.in \
+	$(built_base_sources)
+	set -e; \
+	{ cat $< ; \
+	  echo ; \
+	  for name in $(filter-out Ganeti.THH,$(subst /,.,$(patsubst %.hs,%,$(patsubst htools/%,%,$(HS_LIB_SRCS))))) ; do \
+	    echo "import $$name ()" ; \
+	  done ; \
+	} > $@
+
 lib/_autoconf.py: Makefile | stamp-directories
 	set -e; \
 	{ echo '# This file is automatically generated, do not edit!'; \
@@ -1518,7 +1531,7 @@ hs-apidoc: $(HS_BUILT_SRCS)
 	if [ "$(HTOOLS_PARALLEL3)" ]; \
 	then OPTGHC="$$OPTGHC --optghc=$(HTOOLS_PARALLEL3)"; \
 	fi; \
-	RELSRCS="$(HS_LIB_SRCS:htools/%=%)  $(HS_BUILT_SRCS:htools/%=%)"; \
+	RELSRCS="$(HS_LIB_SRCS:htools/%=%) $(patsubst htools/%,%,$(filter htools/%,$(HS_BUILT_SRCS)))"; \
 	for file in $$RELSRCS; do \
 		hfile=`echo $$file|sed 's/\\.hs$$//'`.html; \
 		$(HSCOLOUR) -css -anchor $$file > ../$(APIDOC_HS_DIR)/$$hfile ; \
diff --git a/htest/Test/Ganeti/TestImports.hs.in b/htest/Test/Ganeti/TestImports.hs.in
new file mode 100644
index 000000000..c26bfa1bd
--- /dev/null
+++ b/htest/Test/Ganeti/TestImports.hs.in
@@ -0,0 +1,7 @@
+-- Hey Emacs, this is a -*- haskell -*- file
+
+{-| Auto-generated file importing all production modules.
+
+-}
+
+module Test.Ganeti.TestImports () where
diff --git a/htest/test.hs b/htest/test.hs
index a56db603b..98cea398a 100644
--- a/htest/test.hs
+++ b/htest/test.hs
@@ -29,7 +29,7 @@ import Data.Monoid (mappend)
 import Test.Framework
 import System.Environment (getArgs)
 
-import Ganeti.HTools.QC ()
+import Test.Ganeti.TestImports ()
 import Test.Ganeti.Confd.Utils
 import Test.Ganeti.HTools.CLI
 import Test.Ganeti.HTools.Cluster
diff --git a/htools/Ganeti/HTools/QC.hs b/htools/Ganeti/HTools/QC.hs
deleted file mode 100644
index 15256141c..000000000
--- a/htools/Ganeti/HTools/QC.hs
+++ /dev/null
@@ -1,100 +0,0 @@
-{-# LANGUAGE TemplateHaskell #-}
-{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-unused-imports #-}
-
--- FIXME: should remove the no-warn-unused-imports option, once we get
--- around to testing function from all modules; until then, we keep
--- the (unused) imports here to generate correct coverage (0 for
--- modules we don't use)
-
-{-| Unittests for ganeti-htools.
-
--}
-
-{-
-
-Copyright (C) 2009, 2010, 2011, 2012 Google Inc.
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301, USA.
-
--}
-
-module Ganeti.HTools.QC
-  () where
-
-import qualified Test.HUnit as HUnit
-import Test.QuickCheck
-import Test.QuickCheck.Monadic (assert, monadicIO, run, stop)
-import Text.Printf (printf)
-import Data.List (intercalate, nub, isPrefixOf, sort, (\\))
-import Data.Maybe
-import qualified Data.Set as Set
-import Control.Monad
-import Control.Applicative
-import qualified System.Console.GetOpt as GetOpt
-import qualified Text.JSON as J
-import qualified Data.Map as Map
-import qualified Data.IntMap as IntMap
-import Control.Concurrent (forkIO)
-import Control.Exception (bracket, catchJust)
-import System.Directory (getTemporaryDirectory, removeFile)
-import System.Environment (getEnv)
-import System.Exit (ExitCode(..))
-import System.IO (hClose, openTempFile)
-import System.IO.Error (isEOFErrorType, ioeGetErrorType, isDoesNotExistError)
-import System.Process (readProcessWithExitCode)
-
-import qualified Ganeti.Confd as Confd
-import qualified Ganeti.Confd.Server as Confd.Server
-import qualified Ganeti.Confd.Utils as Confd.Utils
-import qualified Ganeti.Config as Config
-import qualified Ganeti.Daemon as Daemon
-import qualified Ganeti.Hash as Hash
-import qualified Ganeti.BasicTypes as BasicTypes
-import qualified Ganeti.Jobs as Jobs
-import qualified Ganeti.Logging as Logging
-import qualified Ganeti.Luxi as Luxi
-import qualified Ganeti.Objects as Objects
-import qualified Ganeti.OpCodes as OpCodes
-import qualified Ganeti.Query.Language as Qlang
-import qualified Ganeti.Runtime as Runtime
-import qualified Ganeti.HTools.CLI as CLI
-import qualified Ganeti.HTools.Cluster as Cluster
-import qualified Ganeti.HTools.Container as Container
-import qualified Ganeti.HTools.ExtLoader
-import qualified Ganeti.HTools.Group as Group
-import qualified Ganeti.HTools.IAlloc as IAlloc
-import qualified Ganeti.HTools.Instance as Instance
-import qualified Ganeti.JSON as JSON
-import qualified Ganeti.HTools.Loader as Loader
-import qualified Ganeti.HTools.Luxi as HTools.Luxi
-import qualified Ganeti.HTools.Node as Node
-import qualified Ganeti.HTools.PeerMap as PeerMap
-import qualified Ganeti.HTools.Rapi
-import qualified Ganeti.HTools.Simu as Simu
-import qualified Ganeti.HTools.Text as Text
-import qualified Ganeti.HTools.Types as Types
-import qualified Ganeti.HTools.Utils as Utils
-import qualified Ganeti.HTools.Version
-import qualified Ganeti.Constants as C
-
-import qualified Ganeti.HTools.Program as Program
-import qualified Ganeti.HTools.Program.Hail
-import qualified Ganeti.HTools.Program.Hbal
-import qualified Ganeti.HTools.Program.Hscan
-import qualified Ganeti.HTools.Program.Hspace
-
-import Test.Ganeti.TestHelper (testSuite)
-import Test.Ganeti.TestCommon
-- 
GitLab