Matthew Pickering pushed to branch wip/gdc-files at Glasgow Haskell Compiler / GHC Commits: 35dd8de4 by Matthew Pickering at 2025-08-21T17:13:52+01:00 Add tests - - - - - 17 changed files: - + testsuite/tests/driver/bytecode-object/A.hs - + testsuite/tests/driver/bytecode-object/BytecodeMain.hs - + testsuite/tests/driver/bytecode-object/BytecodeTest.hs - + testsuite/tests/driver/bytecode-object/Makefile - + testsuite/tests/driver/bytecode-object/all.T - + testsuite/tests/driver/bytecode-object/bytecode_object12.stderr - + testsuite/tests/driver/bytecode-object/bytecode_object13.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object14.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object15.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object16.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object17.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object18.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object19.script - + testsuite/tests/driver/bytecode-object/bytecode_object19.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object4.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object5.stdout - + testsuite/tests/driver/bytecode-object/bytecode_object6.stdout Changes: ===================================== testsuite/tests/driver/bytecode-object/A.hs ===================================== @@ -0,0 +1,3 @@ +module BytecodeTest where + +binding = 1 + 1 ===================================== testsuite/tests/driver/bytecode-object/BytecodeMain.hs ===================================== @@ -0,0 +1,4 @@ +module Main where + +main :: IO () +main = putStrLn "Hello from BytecodeMain!" \ No newline at end of file ===================================== testsuite/tests/driver/bytecode-object/BytecodeTest.hs ===================================== @@ -0,0 +1,3 @@ +module BytecodeTest where + +binding = 1 + 1 ===================================== testsuite/tests/driver/bytecode-object/Makefile ===================================== @@ -0,0 +1,128 @@ +TOP=../../.. +include $(TOP)/mk/boilerplate.mk +include $(TOP)/mk/test.mk + +# Test that a .gbc file is emitted. +bytecode_object1: + "$(TEST_HC)" $(TEST_HC_OPTS) BytecodeTest.hs -c -fbyte-code -fwrite-byte-code + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that a -gbcdir works +bytecode_object2: + "$(TEST_HC)" $(TEST_HC_OPTS) -c BytecodeTest.hs -gbcdir=bytecode -fbyte-code -fwrite-byte-code + @[ -d bytecode ] || (echo "ERROR: Expected bytecode directory not found"; echo "Directories in current directory:"; ls -la | grep "^d"; exit 1) + @[ -f bytecode/BytecodeTest.gbc ] || (echo "ERROR: Expected bytecode/BytecodeTest.gbc file not found"; echo "Files in bytecode directory:"; ls -la bytecode/; exit 1) + +# Test that a -gbcsuf works +bytecode_object3: + "$(TEST_HC)" $(TEST_HC_OPTS) -c BytecodeTest.hs -gbcsuf=bc -fbyte-code -fwrite-byte-code + @[ -f BytecodeTest.bc ] || (echo "ERROR: Expected BytecodeTest.bc file not found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that a .gbc file is emitted in --make mode. +bytecode_object4: + "$(TEST_HC)" $(TEST_HC_OPTS) --make -no-link BytecodeTest.hs -fbyte-code -fwrite-byte-code + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that a -gbcdir works in --make mode +bytecode_object5: + "$(TEST_HC)" $(TEST_HC_OPTS) --make -no-link BytecodeTest.hs -gbcdir=bytecode -fbyte-code -fwrite-byte-code + @[ -d bytecode ] || (echo "ERROR: Expected bytecode directory not found"; echo "Directories in current directory:"; ls -la | grep "^d"; exit 1) + @[ -f bytecode/BytecodeTest.gbc ] || (echo "ERROR: Expected bytecode/BytecodeTest.gbc file not found"; echo "Files in bytecode directory:"; ls -la bytecode/; exit 1) + +# Test that a -gbcsuf works in --make mode +bytecode_object6: + "$(TEST_HC)" $(TEST_HC_OPTS) --make -no-link BytecodeTest.hs -gbcsuf=bc -fbyte-code -fwrite-byte-code + @[ -f BytecodeTest.bc ] || (echo "ERROR: Expected BytecodeTest.bc file not found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that both .o and .gbc files are emitted with -fbyte-code-and-object-code +bytecode_object7: + "$(TEST_HC)" $(TEST_HC_OPTS) -c BytecodeTest.hs -fbyte-code-and-object-code -fwrite-byte-code + @[ -f BytecodeTest.o ] || (echo "ERROR: Expected BytecodeTest.o file not found"; echo "Files in current directory:"; ls -la; exit 1) + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that -gbcdir works with -fbyte-code-and-object-code +bytecode_object8: + "$(TEST_HC)" $(TEST_HC_OPTS) -c BytecodeTest.hs -gbcdir=bytecode -fbyte-code-and-object-code -fwrite-byte-code + @[ -f BytecodeTest.o ] || (echo "ERROR: Expected BytecodeTest.o file not found"; echo "Files in current directory:"; ls -la; exit 1) + @[ -d bytecode ] || (echo "ERROR: Expected bytecode directory not found"; echo "Directories in current directory:"; ls -la | grep "^d"; exit 1) + @[ -f bytecode/BytecodeTest.gbc ] || (echo "ERROR: Expected bytecode/BytecodeTest.gbc file not found"; echo "Files in bytecode directory:"; ls -la bytecode/; exit 1) + +# Test that -gbcsuf works with -fbyte-code-and-object-code +bytecode_object9: + "$(TEST_HC)" $(TEST_HC_OPTS) -c BytecodeTest.hs -gbcsuf=bc -fbyte-code-and-object-code -fwrite-byte-code + @[ -f BytecodeTest.o ] || (echo "ERROR: Expected BytecodeTest.o file not found"; echo "Files in current directory:"; ls -la; exit 1) + @[ -f BytecodeTest.bc ] || (echo "ERROR: Expected BytecodeTest.bc file not found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that -fbyte-code alone doesn't produce .hi or .o files +bytecode_object10: + "$(TEST_HC)" $(TEST_HC_OPTS) -c BytecodeTest.hs -fbyte-code + @[ ! -f BytecodeTest.hi ] || (echo "ERROR: Unexpected BytecodeTest.hi file found"; echo "Files in current directory:"; ls -la; exit 1) + @[ ! -f BytecodeTest.o ] || (echo "ERROR: Unexpected BytecodeTest.o file found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test that -fbyte-code alone in --make mode doesn't produce .hi or .o files +bytecode_object11: + "$(TEST_HC)" $(TEST_HC_OPTS) --make -no-link -v0 BytecodeTest.hs -fbyte-code + @[ ! -f BytecodeTest.hi ] || (echo "ERROR: Unexpected BytecodeTest.hi file found"; echo "Files in current directory:"; ls -la; exit 1) + @[ ! -f BytecodeTest.o ] || (echo "ERROR: Unexpected BytecodeTest.o file found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test what happens with -fbyte-code and a Main module in --make mode +bytecode_object12: + "$(TEST_HC)" $(TEST_HC_OPTS) --make -v0 BytecodeMain.hs -fbyte-code + @[ ! -f BytecodeMain.hi ] || (echo "ERROR: Unexpected BytecodeMain.hi file found"; echo "Files in current directory:"; ls -la; exit 1) + @[ ! -f BytecodeMain.o ] || (echo "ERROR: Unexpected BytecodeMain.o file found"; echo "Files in current directory:"; ls -la; exit 1) + @[ ! -f BytecodeMain ] || (echo "ERROR: Unexpected BytecodeMain executable found"; echo "Files in current directory:"; ls -la; exit 1) + +# Test recompilation by generating .gdc first, then starting GHCi +bytecode_object13: + "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic -c BytecodeTest.hs -fbyte-code -fwrite-byte-code -fwrite-interface + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + @echo "Testing recompilation in GHCi..." + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + +# Test recompilation after touching .hi file to make it newer than .gbc file +bytecode_object14: + "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic -c BytecodeTest.hs -fbyte-code -fwrite-byte-code -fwrite-interface + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + @[ -f BytecodeTest.hi ] || (echo "ERROR: Expected BytecodeTest.hi file not found"; echo "Files in current directory:"; ls -la; exit 1) + @touch BytecodeTest.hi + @echo "Testing recompilation in GHCi after touching .hi file..." + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + +# Test recompilation by generating .gbc via --interactive, then starting GHCi again +bytecode_object15: + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + @echo "Testing recompilation in GHCi..." + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + +# Test what happens when .gbc file is deleted before starting GHCi +bytecode_object16: + "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic -c BytecodeTest.hs -fbyte-code -fwrite-byte-code -fwrite-interface + @[ -f BytecodeTest.gbc ] || (echo "ERROR: Expected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + @rm BytecodeTest.gbc + @echo "Testing GHCi startup without .gbc file..." + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs + +# Test what happens with interface file but no bytecode file +# This should recompute from scratch since we are missing the .gbc file +bytecode_object17: + "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic -c BytecodeTest.hs -fwrite-if-simplified-core + @[ -f BytecodeTest.hi ] || (echo "ERROR: Expected BytecodeTest.hi file not found"; echo "Files in current directory:"; ls -la; exit 1) + @[ ! -f BytecodeTest.gbc ] || (echo "ERROR: Unexpected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + @echo "Testing GHCi startup with interface file but no bytecode file..." + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface -fwrite-if-simplified-core BytecodeTest.hs + +# Test what happens with interface file but no bytecode file (without -fwrite-byte-code) +# This should use the bindings in the .hi file to avoid recomputing from scratch. +bytecode_object18: + "$(TEST_HC)" $(TEST_HC_OPTS) -dynamic -c BytecodeTest.hs -fwrite-if-simplified-core + @[ -f BytecodeTest.hi ] || (echo "ERROR: Expected BytecodeTest.hi file not found"; echo "Files in current directory:"; ls -la; exit 1) + @[ ! -f BytecodeTest.gbc ] || (echo "ERROR: Unexpected BytecodeTest.gbc file not found"; echo "Files in current directory:"; ls -la; exit 1) + @echo "Testing GHCi startup with interface file but no bytecode file (without -fwrite-byte-code)..." + @echo ":quit" | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-if-simplified-core -fwrite-interface BytecodeTest.hs + +# Test removing .gbc file and reloading in GHCi +# The module should be recompiled. +bytecode_object19: + @echo "Testing GHCi with .gbc file removal and reload..." + @cat bytecode_object19.script | "$(TEST_HC)" $(TEST_HC_OPTS) --interactive -fbyte-code -fwrite-byte-code -fwrite-interface BytecodeTest.hs ===================================== testsuite/tests/driver/bytecode-object/all.T ===================================== @@ -0,0 +1,19 @@ +test('bytecode_object1', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object1']) +test('bytecode_object2', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object2']) +test('bytecode_object3', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object3']) +test('bytecode_object4', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object4']) +test('bytecode_object5', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object5']) +test('bytecode_object6', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object6']) +test('bytecode_object7', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object7']) +test('bytecode_object8', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object8']) +test('bytecode_object9', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object9']) +test('bytecode_object10', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object10']) +test('bytecode_object11', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object11']) +test('bytecode_object12', [extra_files(['BytecodeTest.hs', 'BytecodeMain.hs'])], makefile_test, ['bytecode_object12']) +test('bytecode_object13', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object13']) +test('bytecode_object14', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object14']) +test('bytecode_object15', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object15']) +test('bytecode_object16', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object16']) +test('bytecode_object17', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object17']) +test('bytecode_object18', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object18']) +test('bytecode_object19', [extra_files(['BytecodeTest.hs'])], makefile_test, ['bytecode_object19']) ===================================== testsuite/tests/driver/bytecode-object/bytecode_object12.stderr ===================================== @@ -0,0 +1,3 @@ +when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)] + Byte-code linking does not currently support linking an executable, enabling -no-link + ===================================== testsuite/tests/driver/bytecode-object/bytecode_object13.stdout ===================================== @@ -0,0 +1,4 @@ +Testing recompilation in GHCi... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +Ok, one module loaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object14.stdout ===================================== @@ -0,0 +1,5 @@ +Testing recompilation in GHCi after touching .hi file... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted )[main] [Missing bytecode] +Ok, one module loaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object15.stdout ===================================== @@ -0,0 +1,8 @@ +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted )[main] +Ok, one module loaded. +ghci> Leaving GHCi. +Testing recompilation in GHCi... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +Ok, one module loaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object16.stdout ===================================== @@ -0,0 +1,5 @@ +Testing GHCi startup without .gbc file... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted )[main] [Missing bytecode] +Ok, one module loaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object17.stdout ===================================== @@ -0,0 +1,5 @@ +Testing GHCi startup with interface file but no bytecode file... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted )[main] [Missing bytecode] +Ok, one module loaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object18.stdout ===================================== @@ -0,0 +1,4 @@ +Testing GHCi startup with interface file but no bytecode file (without -fwrite-byte-code)... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +Ok, one module loaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object19.script ===================================== @@ -0,0 +1,3 @@ +:!rm BytecodeTest.gbc +:reload +:quit \ No newline at end of file ===================================== testsuite/tests/driver/bytecode-object/bytecode_object19.stdout ===================================== @@ -0,0 +1,7 @@ +Testing GHCi with .gbc file removal and reload... +GHCi, version 9.15.20250811: https://www.haskell.org/ghc/ :? for help +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted )[main] +Ok, one module loaded. +ghci> ghci> [1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted )[main] [Missing bytecode] +Ok, one module reloaded. +ghci> Leaving GHCi. ===================================== testsuite/tests/driver/bytecode-object/bytecode_object4.stdout ===================================== @@ -0,0 +1 @@ +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted ) ===================================== testsuite/tests/driver/bytecode-object/bytecode_object5.stdout ===================================== @@ -0,0 +1 @@ +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted ) ===================================== testsuite/tests/driver/bytecode-object/bytecode_object6.stdout ===================================== @@ -0,0 +1 @@ +[1 of 1] Compiling BytecodeTest ( BytecodeTest.hs, interpreted ) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/35dd8de44771a5719cfe75d1edc7aaf1... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/35dd8de44771a5719cfe75d1edc7aaf1... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Matthew Pickering (@mpickering)