[m-rev.] for review: add test case for duplicate instance declarations

Fergus Henderson fjh at cs.mu.OZ.AU
Thu May 17 02:31:37 AEST 2001


Estimated hours taken: 0.75
Branches: main

tests/invalid/Mmakefile:
tests/invalid/duplicate_instance_1.m:
tests/invalid/duplicate_instance_2.m:
tests/invalid/duplicate_instance_2.err_exp:
tests/invalid/duplicate_instance_2.err_exp2:
	Add a test case to test that we report link errors for duplicate
	instance definitions.

tests/invalid/Mmakefile:
	A couple of minor improvements:
	- pass $(ALL_GRADEFLAGS) to $(MC) when creating the .err files
	- use $(DIFF_OPTS) rather than hard-coding `-c'

Workspace: /home/hg/fjh/mercury
Index: tests/invalid/duplicate_instance_1.m
===================================================================
RCS file: duplicate_instance_1.m
diff -N duplicate_instance_1.m
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ duplicate_instance_1.m	Thu May 17 02:06:14 2001
@@ -0,0 +1,6 @@
+:- module duplicate_instance_1.
+:- interface.
+:- typeclass foo(T) where [].
+:- instance foo(int).
+:- implementation.
+:- instance foo(int) where [].
Index: tests/invalid/duplicate_instance_2.err_exp
===================================================================
RCS file: duplicate_instance_2.err_exp
diff -N duplicate_instance_2.err_exp
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ duplicate_instance_2.err_exp	Thu May 17 02:20:06 2001
@@ -0,0 +1,5 @@
+duplicate_instance_2.o(.data+0x0): multiple definition of `<instance declaration for duplicate_instance_1:foo(int/0)>'
+duplicate_instance_1.o(.data+0x0): first defined here
+collect2: ld returned 1 exit status
+Error: system command returned non-zero exit status.
+Error: link failed.
Index: tests/invalid/duplicate_instance_2.err_exp2
===================================================================
RCS file: duplicate_instance_2.err_exp2
diff -N duplicate_instance_2.err_exp2
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ duplicate_instance_2.err_exp2	Thu May 17 02:24:43 2001
@@ -0,0 +1,5 @@
+duplicate_instance_2.o(.rodata+0x0): multiple definition of `base_typeclass_info_duplicate_instance_1__foo__arity1__int__arity0__'
+duplicate_instance_1.o(.rodata+0x0): first defined here
+collect2: ld returned 1 exit status
+Error: system command returned non-zero exit status.
+Error: link failed.
Index: tests/invalid/duplicate_instance_2.m
===================================================================
RCS file: duplicate_instance_2.m
diff -N duplicate_instance_2.m
--- /dev/null	Thu Mar 30 14:06:13 2000
+++ duplicate_instance_2.m	Thu May 17 02:01:48 2001
@@ -0,0 +1,12 @@
+:- module duplicate_instance_2.
+:- interface.
+:- import_module io.
+
+:- pred main(state::di, state::uo) is det.
+
+:- implementation.
+:- import_module duplicate_instance_1.
+
+:- instance foo(int) where [].
+
+main --> [].
Index: tests/invalid/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/tests/invalid/Mmakefile,v
retrieving revision 1.81
diff -u -d -r1.81 Mmakefile
--- tests/invalid/Mmakefile	2001/03/05 02:50:52	1.81
+++ tests/invalid/Mmakefile	2001/05/16 16:25:48
@@ -16,6 +16,7 @@
 	aditi_state_errors.m \
 	aditi_update_errors.m \
 	aditi_update_mode_errors.m \
+	duplicate_instance_2.m \
 	imported_mode.m \
 	partial_implied_mode.m \
 	test_nested.m \
@@ -150,16 +151,28 @@
 ERR_RESS=	$(SOURCES:%.m=%.err_res)
 
 %.err: %.m
-	if $(MC) $(ALL_MCFLAGS) --errorcheck-only $* > $*.err 2>&1; \
+	if $(MC) $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) --errorcheck-only $* \
+		> $*.err 2>&1; \
 	then false; else true; fi
 
+# For duplicate_instance_{1,2}, the error is only caught at link time.
+# So we need to use a different rule for that.
+duplicate_instance_2.err: duplicate_instance_1.m duplicate_instance_2.m \
+		duplicate_instance_1.int
+	if $(MC) $(ALL_GRADEFLAGS) $(ALL_MCFLAGS) \
+		duplicate_instance_1.m duplicate_instance_2.m \
+		> $*.err 2>&1; \
+	then false; else true; fi
+
 # Some tests have more than one possible valid output, so
 # we allow the test to pass if it matches *either* the .err_exp
 # or the .err_exp2 file. 
+DIFF_OPTS=-c
 %.err_res: %.err %.err_exp
 	-rm -f $@
-	diff -c $*.err_exp $*.err > $@ || \
-		{ [ -f $*.err_exp2 ] && diff -c $*.err_exp2 $*.err > $@; }
+	diff $(DIFF_OPTS) $*.err_exp $*.err > $@ || \
+		{ [ -f $*.err_exp2 ] && \
+		  diff $(DIFF_OPTS) $*.err_exp2 $*.err > $@; }
 
 all:	check
 

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list