From e853f9216c65acdd5aff82f2469bd34427cabbaa Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Fri, 23 Aug 2024 13:28:44 -0400 Subject: [PATCH] nitin: add some tests Signed-off-by: Jean Privat --- contrib/nitin/Makefile | 3 +- contrib/nitin/tests.sav | 70 +++++++++++++++++++ contrib/nitin/tests.sh | 9 +++ .../nitin/tests/attribute_initialization.nit | 14 ++++ contrib/nitin/tests/hello.nit | 1 + contrib/nitin/tests/importation.nit | 3 + contrib/nitin/tests/packages.ini | 0 contrib/nitin/tests/refinement.nit | 5 ++ .../nitin/tests/specialization_refinement.nit | 10 +++ contrib/nitin/tests/variables.nit | 6 ++ 10 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 contrib/nitin/tests.sav create mode 100755 contrib/nitin/tests.sh create mode 100644 contrib/nitin/tests/attribute_initialization.nit create mode 100644 contrib/nitin/tests/hello.nit create mode 100644 contrib/nitin/tests/importation.nit create mode 100644 contrib/nitin/tests/packages.ini create mode 100644 contrib/nitin/tests/refinement.nit create mode 100644 contrib/nitin/tests/specialization_refinement.nit create mode 100644 contrib/nitin/tests/variables.nit diff --git a/contrib/nitin/Makefile b/contrib/nitin/Makefile index 7868c4a2e2..f99e958016 100644 --- a/contrib/nitin/Makefile +++ b/contrib/nitin/Makefile @@ -25,8 +25,9 @@ bin/nitin: $(shell $(NITLS) -M nitin.nit) $(NITC) --semi-global nitin.nit -m readline -o bin/nitin .PHONY: check -check: +check: all $(NITUNIT) . + ./tests.sh .PHONY: doc doc: diff --git a/contrib/nitin/tests.sav b/contrib/nitin/tests.sav new file mode 100644 index 0000000000..abb6178f7f --- /dev/null +++ b/contrib/nitin/tests.sav @@ -0,0 +1,70 @@ + +* tests/attribute_initialization.nit +-->class A +...var hello = "Hello" +...end +-->var a1 = new A +-->print a1.hello +Hello +-->redef class A +...var world = "World" +...end +-->var a2 = new A +-->print a2.hello +Hello +-->print a2.world +World +-->print a1.world +12,7--14: Runtime error: Uninitialized attribute _world + print a1.world + ^ +,---- Stack trace -- - - - +| input-8$Sys$main (12,7--14) +`------------------- - - - +-->a1.world = "Monde" +-->print a1.world +Monde +--> +* tests/hello.nit +-->print "Hello, World!" +Hello, World! +--> +* tests/importation.nit +-->var h = "Hello, world!" +-->import base64 +-->print h.encode_base64 +SGVsbG8sIHdvcmxkIQ== +--> +* tests/refinement.nit +-->var i = 42 +-->redef class Int +...fun foo: Int do return self + 1 +...end +-->print(i.foo) +43 +--> +* tests/specialization_refinement.nit +-->class A +...end +-->class B +...end +-->var b: Object = new B +-->print b isa A +false +-->redef class B +...super A +...end +-->print b isa A +true +--> +* tests/variables.nit +-->var i = 42 +-->print(i) +42 +-->i += 1 +-->print(i) +43 +-->i += 1 +-->print(i) +44 +--> \ No newline at end of file diff --git a/contrib/nitin/tests.sh b/contrib/nitin/tests.sh new file mode 100755 index 0000000000..0891879af2 --- /dev/null +++ b/contrib/nitin/tests.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +> tests.out +for i in tests/*nit; do + echo "* $i" + printf "\n* $i\n" >> tests.out + bin/nitin < "$i" >> tests.out +done +diff -u tests.sav tests.out diff --git a/contrib/nitin/tests/attribute_initialization.nit b/contrib/nitin/tests/attribute_initialization.nit new file mode 100644 index 0000000000..0b6d92dee6 --- /dev/null +++ b/contrib/nitin/tests/attribute_initialization.nit @@ -0,0 +1,14 @@ +class A +var hello = "Hello" +end +var a1 = new A +print a1.hello +redef class A +var world = "World" +end +var a2 = new A +print a2.hello +print a2.world +print a1.world +a1.world = "Monde" +print a1.world diff --git a/contrib/nitin/tests/hello.nit b/contrib/nitin/tests/hello.nit new file mode 100644 index 0000000000..5021c79d19 --- /dev/null +++ b/contrib/nitin/tests/hello.nit @@ -0,0 +1 @@ +print "Hello, World!" diff --git a/contrib/nitin/tests/importation.nit b/contrib/nitin/tests/importation.nit new file mode 100644 index 0000000000..ff01dda27b --- /dev/null +++ b/contrib/nitin/tests/importation.nit @@ -0,0 +1,3 @@ +var h = "Hello, world!" +import base64 +print h.encode_base64 diff --git a/contrib/nitin/tests/packages.ini b/contrib/nitin/tests/packages.ini new file mode 100644 index 0000000000..e69de29bb2 diff --git a/contrib/nitin/tests/refinement.nit b/contrib/nitin/tests/refinement.nit new file mode 100644 index 0000000000..d0e48422e5 --- /dev/null +++ b/contrib/nitin/tests/refinement.nit @@ -0,0 +1,5 @@ +var i = 42 +redef class Int +fun foo: Int do return self + 1 +end +print(i.foo) diff --git a/contrib/nitin/tests/specialization_refinement.nit b/contrib/nitin/tests/specialization_refinement.nit new file mode 100644 index 0000000000..9c65751778 --- /dev/null +++ b/contrib/nitin/tests/specialization_refinement.nit @@ -0,0 +1,10 @@ +class A +end +class B +end +var b: Object = new B +print b isa A +redef class B +super A +end +print b isa A diff --git a/contrib/nitin/tests/variables.nit b/contrib/nitin/tests/variables.nit new file mode 100644 index 0000000000..802e72dd5c --- /dev/null +++ b/contrib/nitin/tests/variables.nit @@ -0,0 +1,6 @@ +var i = 42 +print(i) +i += 1 +print(i) +i += 1 +print(i)