Add a testing architecture for the samples directory.

Estimated hours taken: 15

Add a testing architecture for the samples directory.
The tests are in the "tests" subdirectory of the samples
directory.  This keeps them close to the samples, but not close
enough to clutter up the samples.
It also means you don't have to worry about the issue of exactly where
the developer has checked out the CVS tests module.

samples/c_interface/simpler_c_calls_mercury/Mmakefile:
	Update this example to generate a .a file
	instead of directly using $(mercury_lib.os)

samples/tests/*:
	Test cases for all the samples.
This commit is contained in:
Tyson Dowd
2000-02-14 05:28:45 +00:00
parent 4d00f02ec8
commit d64781a3d7
93 changed files with 1511 additions and 4 deletions

View File

@@ -7,10 +7,12 @@ MAIN_TARGET=all
depend: mercury_lib.depend
all: c_main
OBJECTS = c_main.o mercury_lib_init.o $(mercury_lib.os)
OBJECTS = c_main.o mercury_lib_init.o
LIBS = libmercury_lib
LIBSLINK = libmercury_lib.a
c_main: $(OBJECTS)
$(ML) $(MLFLAGS) -o c_main $(OBJECTS) $(MLLIBS)
c_main: $(OBJECTS) $(LIBS)
$(ML) $(MLFLAGS) -o c_main $(OBJECTS) $(LIBSLINK)
#-----------------------------------------------------------------------------#
@@ -26,7 +28,7 @@ RM_C=:
#-----------------------------------------------------------------------------#
c_main.o: mercury_lib.h
c_main.o: mercury_lib.h c_main.c
# to make mercury_lib.h, just compile mercury_lib.m;
# the Mercury compiler will create mercury_lib.h as a side-effect.

View File

@@ -0,0 +1,96 @@
#-----------------------------------------------------------------------------#
#
# Note: Mmake lets you override MCFLAGS for a particular file by setting
# MCFLAGS-foo. Similarly, you can override GRADEFLAGS for a particular
# file by setting both GRADEFLAGS-foo and (for compiling the foo_init.c
# file) GRADEFLAGS-foo_init.
#
# override this with `mmake HAVE_NUPROLOG=yes'
# if you want to rebuild the `.exp' files.
HAVE_NUPROLOG=no
DIFF_OPTS=-c
#-----------------------------------------------------------------------------#
# .PRECIOUS: %.mod %.c %.o %_init.c %.no %.nu %_init.nl %_init.no
%_init.c: Entry
#
# If there is a `.inp' file, then we pipe that in as the command's input.
# If there is a `.arg' file, then we use it as the command's argument
# string.
# Then we run the command, with stdout and stderr both redirected to the
# `.out' file. Finally if the command fails (returns non-zero exit status),
# we print out the contents of the `.out' file. We use `grep . $@ /dev/null'
# to print out the contents, because that precedes each line of output with
# the filename, which is helpful when running a parallel make.
#
%.out: %
{ [ -f $*.inp ] && cat $*.inp; } | \
./$< `{ [ -f $*.arg ] && cat $*.arg; }` > $@ 2>&1 || \
{ grep . $@ /dev/null; exit 1; }
#
# For some test cases, there is more than one valid output.
# We try matching the output with the `.exp' file, and if that
# doesn't succeed, and there is a `.exp2' file, then we try matching
# against that too. If neither succeed, the shorter of the two diffs
# is put into the `.res' file.
#
%.res: %.exp %.out
-rm -f $@
-rm -f $*.res2
diff $(DIFF_OPTS) $*.exp $*.out > $@ || \
{ test -f $*.exp2 && \
if diff $(DIFF_OPTS) $*.exp2 $*.out > $*.res2; then \
cp $*.res2 $@; \
else \
{ test `wc -l < $@` -le `wc -l < $*.res2` || \
cp $*.res2 $@; } && false; \
fi; \
}
#-----------------------------------------------------------------------------#
clean_local: clean_out clean_res
clean_mc: clean_c clean_o clean_out clean_res
clean_out:
rm -f *.out
clean_exp:
rm -f *.exp
clean_res:
rm -f *.res
rm -f *.res2
#
# The `foo' targets make `foo_local' in the current directory before
# recursively making `foo' in all subdirectories. The recursive part
# is handled in individual Mmakefiles.
#
.PHONY: check_local dep_local depend_local all_local
.PHONY: check_subdirs dep_subdirs depend_subdirs realclean_subdirs \
clean_subdirs all_subdirs
check: check_local check_subdirs
dep: dep_local dep_subdirs
depend: depend_local depend_subdirs
realclean: realclean_subdirs
clean: clean_subdirs
all: all_local all_subdirs
SUBDIR_MMAKE = mmake \
GRADE='$(GRADE)' \
EXTRA_CFLAGS='$(EXTRA_CFLAGS)' \
EXTRA_MCFLAGS='$(EXTRA_MCFLAGS)'
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,78 @@
#-----------------------------------------------------------------------------#
SOURCEDIR=$(DEPTH)/../$(THISDIR)
%.m: $(SOURCEDIR)/%.m
cp $(SOURCEDIR)/$@ .
SOURCEDIR_EXTRA_FILES= $(EXTRA_FILES:%=$(SOURCEDIR)/%)
#-----------------------------------------------------------------------------#
SRCS= $(PROGS:%=%.m)
DEPS= $(PROGS:%=%.dep)
DEPENDS=$(PROGS:%=%.depend)
OUTS= $(PROGS:%=%.out) $(TESTS:%=%.out)
RESS= $(PROGS:%=%.res) $(TESTS:%=%.res)
dep_local: $(DEPS)
depend_local: extra_files $(SRCS) $(DEPENDS)
check_local: $(OUTS) $(RESS)
all_local: $(PROGS) $(TESTS)
clean_local: clean_srcs clean_extra_files
clean_srcs:
rm -f $(SRCS)
clean_extra_files:
rm -f $(EXTRA_FILES)
extra_files: $(SOURCEDIR_EXTRA_FILES)
-{ [ -n "$(SOURCEDIR_EXTRA_FILES)" ] && cp $(SOURCEDIR_EXTRA_FILES) . || true ; }
#-----------------------------------------------------------------------------#
realclean:
rm -f $(SRCS) $(EXTRA_FILES)
SUBDIRS =
ifeq ($(SUBDIRS),"")
dep_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(SUBDIR_MMAKE) dep) || exit 1; \
done
depend_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(SUBDIR_MMAKE) depend) || exit 1; \
done
check_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(SUBDIR_MMAKE) check) || exit 1; \
done
all_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(SUBDIR_MMAKE) all) || exit 1; \
done
clean_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(SUBDIR_MMAKE) clean) || exit 1; \
done
realclean_subdirs:
for dir in $(SUBDIRS); do \
(cd $$dir && $(SUBDIR_MMAKE) realclean) || exit 1; \
done
else
endif
#-----------------------------------------------------------------------------#

37
samples/tests/Mmakefile Normal file
View File

@@ -0,0 +1,37 @@
SUBDIRS = benchmarks general hard_coded invalid misc_tests tabling term valid warnings
NUPROLOG_SUBDIRS = benchmarks general
main_target: check
# Generate the .exp files that are used as a basis of comparison to check
# the correctness of the code emitted by the Mercury compiler.
exp:
for dir in $(NUPROLOG_SUBDIRS); do \
(cd $$dir && mmake $(MMAKEFLAGS) exp) || exit 1; \
done
# run the tests
check:
for dir in $(SUBDIRS); do \
(cd $$dir && mmake $(MMAKEFLAGS) check) || exit 1; \
done
dep:
for dir in $(SUBDIRS); do \
(cd $$dir && mmake $(MMAKEFLAGS) dep) || exit 1; \
done
depend:
for dir in $(SUBDIRS); do \
(cd $$dir && mmake $(MMAKEFLAGS) depend) || exit 1; \
done
realclean:
for dir in $(SUBDIRS); do \
(cd $$dir && mmake $(MMAKEFLAGS) realclean) || exit 1; \
done
clean:
for dir in $(SUBDIRS); do \
(cd $$dir && mmake $(MMAKEFLAGS) clean) || exit 1; \
done

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=..
THISDIR=c_interface
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,14 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=short_example
TESTS=
EXTRA_FILES=
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/c_calls_mercury
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,29 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=mercury_main
TESTS=
EXTRA_FILES=c_main.c c_main.h
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#
include $(SOURCEDIR)/Mmakefile
# Add a few dependencies so that it copies the source
# files correctly.
mercury_lib.o: mercury_lib.m
mercury_main.depend: c_main_int.m
c_main_int.o: c_main.h
clean_local: clean_2
clean_2:
rm -f *.h *.c *.m mercury_lib.*
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,15 @@
In Mercury main, about to call c_main...
In c_main().
foo_test(42) returns TRUE
foo_test(43) returns FALSE
one_foo(&value) gives value = 42
foo_list() = [42, 53, 197]
bar(100) = 101
bar_test(100, 101) returns TRUE
bar_test(100, 200) returns FALSE
bar_inverse(&value, 101) gives value = 100
bar_inverse(&value, 200) gives value = 199
baz(1, &value) returns TRUE with value = 9
baz(100, &value) returns FALSE
Returning from c_main()...
Back in Mercury main.

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/cplusplus_calls_mercury
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,15 @@
In Mercury main, about to call cpp_main...
In cpp_main().
foo_test(42) returns TRUE
foo_test(43) returns FALSE
one_foo(&value) gives value = 42
foo_list() = [42, 53, 197]
bar(100) = 101
bar_test(100, 101) returns TRUE
bar_test(100, 200) returns FALSE
bar_inverse(&value, 101) gives value = 100
bar_inverse(&value, 200) gives value = 199
baz(1, &value) returns TRUE with value = 9
baz(100, &value) returns FALSE
Returning from cpp_main()...
Back in Mercury main.

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/mercury_calls_c
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,27 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=mercury_main
TESTS=
EXTRA_FILES=c_main.c c_main.h
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#
include $(SOURCEDIR)/Mmakefile
# Add a few dependencies so that it copies the source
# files correctly.
mercury_main.depend: c_main_int.m
clean_local: clean_2
clean_2:
rm -f *.m
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,3 @@
In Mercury main, about to call c_main...
In c_main().
Back in Mercury main.

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/mercury_calls_cplusplus
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,27 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=mercury_main
TESTS=
EXTRA_FILES=cpp_main.c cpp_main.h
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#
include $(SOURCEDIR)/Mmakefile
# Add a few dependencies so that it copies the source
# files correctly.
mercury_main.depend: cpp_main_int.m
clean_local: clean_2
clean_2:
rm -f *.m
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,3 @@
In Mercury main, about to call cpp_main...
In cpp_main().
Back in Mercury main.

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/mercury_calls_fortran
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,28 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=mercury_main
TESTS=
EXTRA_FILES=fortran_main.f
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#
include $(SOURCEDIR)/Mmakefile
# Add a few dependencies so that it copies the source
# files correctly.
mercury_main.depend: fortran_main_int.m
#fortran_main_int.o: fortran_main.f
clean_local: clean_2
clean_2:
rm -f *.m
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,3 @@
In Mercury main, about to call fortran_main...
In FORTRAN_MAIN
Back in Mercury main.

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,2 @@
Hello, world

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/simpler_c_calls_mercury
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,27 @@
#-----------------------------------------------------------------------------#
#
main_target: check
PROGS=
TESTS=c_main
EXTRA_FILES=c_main.c
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#
depend_local: mercury_lib.depend
mercury_lib.depend: mercury_lib.m
include $(SOURCEDIR)/Mmakefile
clean_local: clean_2
clean_2:
rm -f *.h *.c *.m mercury_lib.*
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,13 @@
In main().
foo_test(42) returns TRUE
foo_test(43) returns FALSE
one_foo(&value) gives value = 42
foo_list() = [42, 53, 197]
bar(100) = 101
bar_test(100, 101) returns TRUE
bar_test(100, 200) returns FALSE
bar_inverse(&value, 101) gives value = 100
bar_inverse(&value, 200) gives value = 199
baz(1, &value) returns TRUE with value = 9
baz(100, &value) returns FALSE
Returning from main().

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=../..
THISDIR=c_interface/simpler_cplusplus_calls_mercury
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,27 @@
#-----------------------------------------------------------------------------#
#
main_target: check
PROGS=
TESTS=cpp_main
EXTRA_FILES=cpp_main.cc
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#
depend_local: mercury_lib.depend
mercury_lib.depend: mercury_lib.m
include $(SOURCEDIR)/Mmakefile
clean_local: clean_2
clean_2:
rm -f *.h *.c *.m mercury_lib.*
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,13 @@
In main().
foo_test(42) returns TRUE
foo_test(43) returns FALSE
one_foo(&value) gives value = 42
foo_list() = [42, 53, 197]
bar(100) = 101
bar_test(100, 101) returns TRUE
bar_test(100, 200) returns FALSE
bar_inverse(&value, 101) gives value = 100
bar_inverse(&value, 200) gives value = 199
baz(1, &value) returns TRUE with value = 9
baz(100, &value) returns FALSE
Returning from main().

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=..
THISDIR=diff
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,16 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=diff
TESTS=
EXTRA_FILES=diff_out.m difftype.m file.m filter.m globals.m \
match.m myers.m options.m
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1 @@
-u diff.test.1 diff.test.2

View File

@@ -0,0 +1,10 @@
--- diff.test.1
+++ diff.test.2
@@ -1,5 +1,7 @@
Hello
World
+How interesting an additional line
+
This
is a test

View File

@@ -0,0 +1,5 @@
Hello
World
This
is a test

View File

@@ -0,0 +1,7 @@
Hello
World
How interesting an additional line
This
is a test

47
samples/tests/diff/runtests Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

15
samples/tests/generate_exp Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/sh
# Generate the .exp files that are used as a basis of comparison to check
# the correctness of the code emitted by the Mercury compiler.
. ./handle_options
root=`pwd`
for dir in benchmarks general
do
cd $dir
mmake $jfactor realclean
mmake $jfactor depend
mmake $jfactor HAVE_NUPROLOG=yes exp
cd $root
done

View File

@@ -0,0 +1,84 @@
usage="\
Usage: $0 [options]
Options:
-f <mcflags>, --flags <mcflags>
Pass EXTRA_MCFLAGS=<mcflags> as an option to \`mmake check'.
-m <mgnucflags>, --mgnucflags <mgnucflags>
Pass EXTRA_MGNUCFLAGS=<mgnucflags> as an option to \`mmake check'.
-c <cflags>, --cflags <cflags>
Pass EXTRA_CFLAGS=<cflags> as an option to \`mmake check'.
-l <mlflags>, --mlflags <mlflags>
Pass EXTRA_MLFLAGS=<mlflags> as an option to \`mmake check'.
-g <grade>, --grade <grade>
Pass GRADE=<grade> as an option to \`mmake check'.
-j <num-jobs>, --jobs <num-jobs>
Run using <num-jobs> different parallel processes.
"
jfactor=""
flagsopt=""
mgnucflagsopt=""
cflagsopt=""
mlflagsopt=""
gradeopt=""
fflag=""
mflag=""
cflag=""
lflag=""
gflag=""
while [ $# -gt 0 ]; do
case "$1" in
-f|--flags)
fflag="-f '$2'"
flagsopt="EXTRA_MCFLAGS='$2'"
shift ;;
-m|--mgnucflags)
mflag="-m '$2'"
mgnucflagsopt="EXTRA_MGNUCFLAGS='$2'"
shift ;;
-c|--cflags)
cflag="-c '$2'"
cflagsopt="EXTRA_CFLAGS='$2'"
shift ;;
-l|--mlflags)
lflag="-l '$2'"
mlflagsopt="EXTRA_MLFLAGS='$2'"
shift ;;
-g|--grade)
gflag="-g $2"
gradeopt="GRADE=$2"
shift ;;
-j|--jobs)
jfactor="-j$2"; shift ;;
-j*)
jfactor="-j` expr $1 : '-j\(.*\)' `" ;;
--jobs*)
jfactor="--jobs` expr $1 : '--jobs\(.*\)' `" ;;
--)
shift; break ;;
-*)
echo "$0: unknown option \`$1'" 1>&2
echo "$usage" 1>&2
exit 1 ;;
*)
break ;;
esac
shift
done
if [ $# -ne 0 ]; then
echo "$0: unexpected argument(s) \`$*'" 1>&2
echo "$usage" 1>&2
exit 1
fi
mmakeopts="$jfactor $flagsopt $mgnucflagsopt $cflagsopt $mlflagsopt $gradeopt"
runtestopts="$jfactor $mflag $cflag $lflag $fflag $gflag"

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=..
THISDIR=muz
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,17 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS=muz
TESTS=
EXTRA_FILES=dict.m example.tex example1.tex higher_order.m muz.m \
toolkit.tex typecheck.m word.m zabstract.m zlogic.m zparser.m \
ztoken.m ztoken_io.m ztype.m ztype_op.m
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1 @@
-t toolkit.tex example.tex

View File

@@ -0,0 +1 @@
No errors detected.

47
samples/tests/muz/runtests Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=..
THISDIR=rot13
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,17 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS= rot13_concise \
rot13_verbose \
rot13_gustavo \
rot13_juergen
TESTS=
MCFLAGS-rot13_concise=--infer-all
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,2 @@
N yvggyr grfg bs gur ebg13 cebtenz.
A little test of the rot13 program.

View File

@@ -0,0 +1,2 @@
A little test of the rot13 program.
N yvggyr grfg bs gur ebg13 cebtenz.

View File

@@ -0,0 +1,2 @@
N yvggyr grfg bs gur ebg13 cebtenz.
A little test of the rot13 program.

View File

@@ -0,0 +1,2 @@
A little test of the rot13 program.
N yvggyr grfg bs gur ebg13 cebtenz.

View File

@@ -0,0 +1,2 @@
N yvggyr grfg bs gur ebg13 cebtenz.
A little test of the rot13 program.

View File

@@ -0,0 +1,2 @@
A little test of the rot13 program.
N yvggyr grfg bs gur ebg13 cebtenz.

View File

@@ -0,0 +1,2 @@
N yvggyr grfg bs gur ebg13 cebtenz.
A little test of the rot13 program.

View File

@@ -0,0 +1,2 @@
A little test of the rot13 program.
N yvggyr grfg bs gur ebg13 cebtenz.

45
samples/tests/rot13/runtests Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. ../handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. ../subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. ../startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. ../shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

18
samples/tests/runtests Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
# Process command line options.
. ./handle_options
# Run the tests in each of the subdirectories.
. ./subdir_runtests
if test "$subdir_failures" = ""
then
echo "all tests have succeeded"
echo "mmakeopts=$mmakeopts"
exit 0
else
echo "some tests have failed in: $subdir_failures"
echo "mmakeopts=$mmakeopts"
exit 1
fi

4
samples/tests/shutdown Normal file
View File

@@ -0,0 +1,4 @@
echo cleaning up the directory after the tests
mmake $gradeopt $jfactor realclean_local > /dev/null 2>&1
rm core > /dev/null 2>&1
touch CLEAN

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=..
THISDIR=solutions
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,17 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS= all_solutions \
one_solution \
some_solutions
TESTS=
EXTRA_FILES=
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,2 @@
Hello again, world
Hello, world

View File

@@ -0,0 +1 @@
Hello, world

View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,4 @@
Hello, world
More? Good day, world
More? Greetings, world
More? No (more) solutions

View File

@@ -0,0 +1,3 @@
y
y
y

8
samples/tests/startup Normal file
View File

@@ -0,0 +1,8 @@
echo cleaning up the directory before the tests
if ls -lt | head -2 | egrep CLEAN > /dev/null 2>&1
then
rm -f CLEAN > /dev/null 2>&1
else
rm -f CLEAN > /dev/null 2>&1
mmake $gradeopt -j realclean_local > /dev/null 2>&1
fi

View File

@@ -0,0 +1,20 @@
# Run the tests in each of the subdirectories.
subdir_failures=""
for dir in *
do
if test -d $dir -a -x $dir/runtests
then
cd $dir
# we need to use `eval' here to get the quoting right in
# the case when $runtestopts contains embedded spaces
if eval ./runtests $runtestopts
then
true
else
subdir_failures="$subdir_failures $dir"
fi
cd ..
fi
done

View File

@@ -0,0 +1,6 @@
#-----------------------------------------------------------------------------#
DEPTH=..
THISDIR=.
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,20 @@
#-----------------------------------------------------------------------------#
main_target: check
PROGS= calculator \
cat \
e \
eliza \
expand_terms \
hello \
interpreter \
sort \
ultra_sub
TESTS=
include Mmake.thisdir
include $(DEPTH)/Mmake.common
include $(DEPTH)/Mmake.common.samples
#-----------------------------------------------------------------------------#

View File

@@ -0,0 +1,2 @@
calculator> 7
calculator> EOF

View File

@@ -0,0 +1 @@
3+4

View File

@@ -0,0 +1,2 @@
A test of
the cat program.

View File

@@ -0,0 +1,2 @@
A test of
the cat program.

View File

@@ -0,0 +1,13 @@
2.7182818284590452353602874713526624977572470936999595749669676277240766303535
475945713821785251664274274663919320030599218174135966290435729003342952605956
307381323286279434907632338298807531952510190115738341879307021540891499348841
675092447614606680822648001684774118537423454424371075390777449920695517027618
386062613313845830007520449338265602976067371132007093287091274437470472306969
772093101416928368190255151086574637721112523897844250569536967707854499699679
468644549059879316368892300987931277361782154249992295763514822082698951936680
331825288693984964651058209392398294887933203625094431173012381970684161403970
198376793206832823764648042953118023287825098194558153017567173613320698112509
961818815930416903515988885193458072738667385894228792284998920868058257492796
104841984443634632449684875602336248270419786232090021609902353043699418491463
140934317381436405462531520961836908887070167683964243781405927145635490613031
072085103837505101157477041718986106873969655212671546889570350354

View File

@@ -0,0 +1,12 @@
Hi! I'm Eliza. Please tell me your problem.
>
Don't you really know mercury?
>
You seem quite positive.
>
Goodbye.

View File

@@ -0,0 +1,2 @@
I don't know mercury
yes

View File

@@ -0,0 +1 @@
A :- B.

View File

@@ -0,0 +1 @@
A <=> B.

View File

@@ -0,0 +1 @@
Hello, world

View File

@@ -0,0 +1 @@
interpreter_test.pl

View File

@@ -0,0 +1,7 @@
Pure Prolog Interpreter.
Consulting file `interpreter_test.pl'...
?- sibling(mary, george).
Yes.
?- No.
?-

View File

@@ -0,0 +1,2 @@
sibling(mary, george).
sibling(jane, george).

View File

@@ -0,0 +1,16 @@
father(john, mary).
father(john, andrew).
mother(jane, mary).
mother(jane, andrew).
mother(jane, george).
sibling(X, Y) :-
(
father(F, X), father(F, Y)
;
mother(M, X), mother(M, Y)
).

47
samples/tests/toplevel/runtests Executable file
View File

@@ -0,0 +1,47 @@
#!/bin/sh
# Test whether the code generated by the Mercury compiler
# is producing the expected output.
# Return a status of 0 (true) if everything is all right, and 1 otherwise.
. Mmake.thisdir
. $DEPTH/handle_options
# Run the tests in any subdirectories of this one. If any of these
# fail, we still perform the tests in this directory but return a
# status of 1 regardless of the outcome.
. $DEPTH/subdir_runtests
if test "$subdir_failures" = ""
then
subdir_status=0
else
subdir_status=1
fi
# Now run all the tests in this directory.
. $DEPTH/startup
eval mmake $mmakeopts depend_local || exit 1
eval mmake -k $mmakeopts check_local
checkstatus=$?
pwdir=`pwd`
thisdirname=`basename $pwdir`
cat *.res > .allres
if test ! -s .allres -a "$checkstatus" = 0
then
echo "the tests in the $thisdirname directory succeeded"
echo "mmakeopts=$mmakeopts"
rm -f .allres
. $DEPTH/shutdown
exit $subdir_status
else
echo "the tests in the $thisdirname directory failed"
echo "mmakeopts=$mmakeopts"
echo "the differences are:"
cat .allres
exit 1
fi

View File

@@ -0,0 +1,4 @@
a
b
c
d

View File

@@ -0,0 +1,4 @@
b
c
a
d

View File

@@ -0,0 +1 @@
Xoo Xay foo bar baz

View File

@@ -0,0 +1 @@
fay

View File

@@ -0,0 +1 @@
foo bar baz