<commit_before>TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk

# A set of driver tests

# Things to test:
#
#  - one-shot vs. --make
#  - hierarchical vs. flat
#  - -odir vs. no -odir
#  - -hidir vs. no -hidir
#  - root module vs. found modules

OBJSUFFIX = .o

# -----------------------------------------------------------------------------
# One-shot compilations, non-hierarchical modules

test011:
	@$(RM) A.hi
	@$(RM) A$(OBJSUFFIX)
	$(TEST_HC) -c A.hs
	test -f A.hi
	test -f A$(OBJSUFFIX)

# test -o
test012:
	@$(RM) A.hi
	@$(RM) A$(OBJSUFFIX)oo
	$(TEST_HC) -c A.hs -o A$(OBJSUFFIX)oo
	test -f A$(OBJSUFFIX)oo

# test -ohi
test013:
	@$(RM) A.xhi
	@$(RM) A$(OBJSUFFIX)
	$(TEST_HC) -c A.hs -ohi A.xhi
	test -f A.xhi

# test -odir
test014:
	@$(RM) A.hi
	@$(RM) obj/A$(OBJSUFFIX)
	@$(MKDIRHIER) obj
	$(TEST_HC) -c A.hs -odir obj
	test -f obj/A$(OBJSUFFIX)

# test -hidir
test015:
	@$(RM) hi/A.hi
	@$(RM) A$(OBJSUFFIX)
	@$(MKDIRHIER) hi
	$(TEST_HC) -c A.hs -hidir hi
	test -f hi/A.hi

# test stub generation
test016:
	@$(RM) F.hi F$(OBJSUFFIX) F_stub.c F_stub.h
	@$(TEST_HC) -c F.hs
	test -f F_stub$(OBJSUFFIX)
	test -f F_stub.c
	test -f F_stub.h

# test -stubdir (filename differs from module name)
test017:
	@$(RM) F.hi F$(OBJSUFFIX) stub/TestStub_stub.c stub/TestStub_stub.h stub/TestStub_stub$(OBJSUFFIX) F_stub$(OBJSUFFIX) 
	@$(TEST_HC) -c F.hs -stubdir stub
	test -f F_stub$(OBJSUFFIX)
	test -f stub/TestStub_stub.c
	test -f stub/TestStub_stub.h

# test -odir with stubs (filename differs from module name)
test018:
	@$(RM) F.hi F$(OBJSUFFIX) F_stub.c F_stub.h obj/TestStub_stub$(OBJSUFFIX)
	@$(MKDIRHIER) obj
	@$(TEST_HC) -c F.hs -odir obj
	test -f obj/TestStub_stub$(OBJSUFFIX)

# -----------------------------------------------------------------------------
# One-shot compilation, hierarchical modules

test021:
	@$(RM) B/C.hi
	@$(RM) B/C$(OBJSUFFIX)
	$(TEST_HC) -c B/C.hs
	test -f B/C.hi
	test -f B/C$(OBJSUFFIX)

# test -o
test022:
	@$(RM) B/C.hi
	@$(RM) B/C$(OBJSUFFIX)oo
	$(TEST_HC) -c B/C.hs -o B/C$(OBJSUFFIX)oo
	test -f B/C$(OBJSUFFIX)oo

# test -ohi
test023:
	@$(RM) B/C.xhi
	@$(RM) B/C$(OBJSUFFIX)
	$(TEST_HC) -c B/C.hs -ohi B/C.xhi
	test -f B/C.xhi

# test -odir
test024:
	@$(MKDIRHIER) obj
	@$(RM) B/C.hi
	@$(RM) obj/B/C$(OBJSUFFIX)
	@-rmdir obj/B
	$(TEST_HC) -c B/C.hs -odir obj
	test -f obj/B/C$(OBJSUFFIX)

# test -odir with non-Haskell compilation
test024a:
	@$(MKDIRHIER) obj
	@$(RM) B/stub.c
	@$(RM) obj/B/stub$(OBJSUFFIX)
	@-rmdir obj/B
	@echo >B/stub.c
	$(TEST_HC) -c B/stub.c -odir obj
	test -f obj/B/stub$(OBJSUFFIX)

# test -hidir
test025:
	@$(MKDIRHIER) hi
	@$(RM) hi/B/C.hi
	@$(RM) B/C$(OBJSUFFIX)
	$(TEST_HC) -c B/C.hs -hidir hi
	test -f hi/B/C.hi

# This is a hierarchical module that lives in a subdirectory.
test026:
	@$(RM) d1/P/Q.hi
	@$(RM) d1/P/Q$(OBJSUFFIX)
	$(TEST_HC) -c d1/P/Q.hs
	test -f d1/P/Q.hi
	test -f d1/P/Q$(OBJSUFFIX)

# test stub generation
test027:
	@$(RM) B/F.hi B/F$(OBJSUFFIX) B/F_stub.c B/F_stub.h
	@$(TEST_HC) -c B/F.hs
	test -f B/F_stub.c
	test -f B/F_stub.h

# test -stubdir
test028:
	@$(RM) B/F.hi B/F$(OBJSUFFIX) stub/B/F_stub.c stub/B/F_stub.h
	@$(TEST_HC) -c B/F.hs -stubdir stub
	test -f stub/B/F_stub.c
	test -f stub/B/F_stub.h

# -----------------------------------------------------------------------------
# Compilation-manager compilations, flat modules

test031:
	@$(RM) A.hi
	@$(RM) A$(OBJSUFFIX)
	$(TEST_HC) --make A.hs
	test -f A.hi
	test -f A$(OBJSUFFIX)

# test -odir
test032:
	@$(RM) A.hi<commit_msg>driver027/driver028 need to use -fvia-C to expose a bug in -stubdir<commit_after>TOP=../../..
include $(TOP)/mk/boilerplate.mk
include $(TOP)/mk/test.mk

# A set of driver tests

# Things to test:
#
#  - one-shot vs. --make
#  - hierarchical vs. flat
#  - -odir vs. no -odir
#  - -hidir vs. no -hidir
#  - root module vs. found modules

OBJSUFFIX = .o

# -----------------------------------------------------------------------------
# One-shot compilations, non-hierarchical modules

test011:
	@$(RM) A.hi
	@$(RM) A$(OBJSUFFIX)
	$(TEST_HC) -c A.hs
	test -f A.hi
	test -f A$(OBJSUFFIX)

# test -o
test012:
	@$(RM) A.hi
	@$(RM) A$(OBJSUFFIX)oo
	$(TEST_HC) -c A.hs -o A$(OBJSUFFIX)oo
	test -f A$(OBJSUFFIX)oo

# test -ohi
test013:
	@$(RM) A.xhi
	@$(RM) A$(OBJSUFFIX)
	$(TEST_HC) -c A.hs -ohi A.xhi
	test -f A.xhi

# test -odir
test014:
	@$(RM) A.hi
	@$(RM) obj/A$(OBJSUFFIX)
	@$(MKDIRHIER) obj
	$(TEST_HC) -c A.hs -odir obj
	test -f obj/A$(OBJSUFFIX)

# test -hidir
test015:
	@$(RM) hi/A.hi
	@$(RM) A$(OBJSUFFIX)
	@$(MKDIRHIER) hi
	$(TEST_HC) -c A.hs -hidir hi
	test -f hi/A.hi

# test stub generation
test016:
	@$(RM) F.hi F$(OBJSUFFIX) F_stub.c F_stub.h
	@$(TEST_HC) -c F.hs
	test -f F_stub$(OBJSUFFIX)
	test -f F_stub.c
	test -f F_stub.h

# test -stubdir (filename differs from module name)
test017:
	@$(RM) F.hi F$(OBJSUFFIX) stub/TestStub_stub.c stub/TestStub_stub.h stub/TestStub_stub$(OBJSUFFIX) F_stub$(OBJSUFFIX) 
	@$(TEST_HC) -c F.hs -stubdir stub
	test -f F_stub$(OBJSUFFIX)
	test -f stub/TestStub_stub.c
	test -f stub/TestStub_stub.h

# test -odir with stubs (filename differs from module name)
test018:
	@$(RM) F.hi F$(OBJSUFFIX) F_stub.c F_stub.h obj/TestStub_stub$(OBJSUFFIX)
	@$(MKDIRHIER) obj
	@$(TEST_HC) -c F.hs -odir obj
	test -f obj/TestStub_stub$(OBJSUFFIX)

# -----------------------------------------------------------------------------
# One-shot compilation, hierarchical modules

test021:
	@$(RM) B/C.hi
	@$(RM) B/C$(OBJSUFFIX)
	$(TEST_HC) -c B/C.hs
	test -f B/C.hi
	test -f B/C$(OBJSUFFIX)

# test -o
test022:
	@$(RM) B/C.hi
	@$(RM) B/C$(OBJSUFFIX)oo
	$(TEST_HC) -c B/C.hs -o B/C$(OBJSUFFIX)oo
	test -f B/C$(OBJSUFFIX)oo

# test -ohi
test023:
	@$(RM) B/C.xhi
	@$(RM) B/C$(OBJSUFFIX)
	$(TEST_HC) -c B/C.hs -ohi B/C.xhi
	test -f B/C.xhi

# test -odir
test024:
	@$(MKDIRHIER) obj
	@$(RM) B/C.hi
	@$(RM) obj/B/C$(OBJSUFFIX)
	@-rmdir obj/B
	$(TEST_HC) -c B/C.hs -odir obj
	test -f obj/B/C$(OBJSUFFIX)

# test -odir with non-Haskell compilation
test024a:
	@$(MKDIRHIER) obj
	@$(RM) B/stub.c
	@$(RM) obj/B/stub$(OBJSUFFIX)
	@-rmdir obj/B
	@echo >B/stub.c
	$(TEST_HC) -c B/stub.c -odir obj
	test -f obj/B/stub$(OBJSUFFIX)

# test -hidir
test025:
	@$(MKDIRHIER) hi
	@$(RM) hi/B/C.hi
	@$(RM) B/C$(OBJSUFFIX)
	$(TEST_HC) -c B/C.hs -hidir hi
	test -f hi/B/C.hi

# This is a hierarchical module that lives in a subdirectory.
test026:
	@$(RM) d1/P/Q.hi
	@$(RM) d1/P/Q$(OBJSUFFIX)
	$(TEST_HC) -c d1/P/Q.hs
	test -f d1/P/Q.hi
	test -f d1/P/Q$(OBJSUFFIX)

# test stub generation
# -fvia-C, because we want to check that the .hc file can #include the stub.h
test027:
	@$(RM) B/F.hi B/F$(OBJSUFFIX) B/F_stub.c B/F_stub.h
	@$(TEST_HC) -c B/F.hs -fvia-C
	test -f B/F_stub.c
	test -f B/F_stub.h

# test -stubdir
# -fvia-C, because we want to check that the .hc file can #include the stub.h
test028:
	@$(RM) B/F.hi B/F$(OBJSUFFIX) stub/B/F_stub.c stub/B/F_stub.h
	@$(TEST_HC) -c B/F.hs -stubdir stub -fvia-C
	test -f stub/B/F_stub.c
	test -f stub/B/F_stub.h

# -----------------------------------------------------------------------------
# Compilation-manager compilations, flat modules

test031:
	@$(RM) A.hi
	@$(RM) A$(OBJSUFFIX)
	$(TEST_HC) --make A.hs
	test -f A.hi
	test -f A$(OBJSUFFIX)

# test -odir
test032:
	@$(RM) A.hi
{'fraction_non_alphanumeric': 0.24405749032614704, 'fraction_numerical': 0.017965726920950803, 'mean_word_length': 2.4347413383958236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4544701', 'n_tokens_mistral': 3603, 'n_tokens_neox': 3509, 'n_words': 807}