1#!/usr/bin/perl 2 3# Z88DK Z80 Module Assembler 4# 5# Copyright (C) Paulo Custodio, 2011-2020 6# License: The Artistic License 2.0, http://www.perlfoundation.org/artistic_license_2_0 7# Repository: https://github.com/z88dk/z88dk/ 8# 9# Test INCLUDE 10 11use Modern::Perl; 12use Test::More; 13require './t/testlib.pl'; 14 15# no -I, multiple levels 16unlink_testfiles(); 17spew("test0.inc", 'ld a,10'); 18for (1..9) { spew("test$_.inc", 'include "test'.($_-1).'.inc"'."\n defb $_"); } 19z80asm(<<END); 20 include "test9.inc" 21 nop 22END 23check_bin_file("test.bin", pack("C*", 0x3E, 10, 1..9, 0)); 24 25# -I 26unlink_testfiles(); 27mkdir("test_dir"); 28 29spew("test_dir/test.inc", 'ld a,10'); 30 31# no -I, full path : OK 32z80asm('include "test_dir/test.inc"'); 33check_bin_file("test.bin", pack("C*", 0x3E, 10)); 34 35# no -I, only file name : error 36z80asm('include "test.inc"', "", 1, "", <<END); 37Error at file 'test.asm' line 1: cannot read file 'test.inc' 38END 39 40# -I : OK 41z80asm('include "test.inc"', "-b -Itest_dir"); 42check_bin_file("test.bin", pack("C*", 0x3E, 10)); 43 44# -I, full path : OK 45z80asm('include "test_dir/test.inc"', "-b -Itest_dir"); 46check_bin_file("test.bin", pack("C*", 0x3E, 10)); 47 48# directory of source file is added to include path 49unlink_testfiles(); 50mkdir("test_dir"); 51 52spew("test_dir/test.inc", 'ld a,10'); 53spew("test_dir/test.asm", 'include "test.inc"'); 54run("z80asm -b test_dir/test.asm"); 55check_bin_file("test_dir/test.bin", pack("C*", 0x3E, 10)); 56 57# error_read_file 58# BUG_0034 : If assembly process fails with fatal error, invalid library is kept 59unlink_testfiles(); 60z80asm('include "test.inc"', "-xtest.lib", 1, "", <<END); 61Error at file 'test.asm' line 1: cannot read file 'test.inc' 62END 63ok ! -f "test.lib", "test.lib does not exist"; 64 65# error_include_recursion 66unlink_testfiles(); 67spew("test.inc", 'include "test.asm"'); 68z80asm('include "test.inc"', "", 1, "", <<END); 69Error at file 'test.inc' line 1: cannot include file 'test.asm' recursively 70END 71 72# syntax 73unlink_testfiles(); 74z80asm('include', "", 1, "", <<END); 75Error at file 'test.asm' line 1: syntax error 76END 77 78# test -I using environment variables 79unlink_testfiles(); 80mkdir("test_dir"); 81 82spew("test_dir/test.inc", 'ld a,10'); 83 84unlink "test.bin"; 85z80asm('include "test.inc"', "", 1, "", <<END); 86Error at file 'test.asm' line 1: cannot read file 'test.inc' 87END 88 89unlink "test.bin"; 90z80asm('include "test.inc"', "-b -Itest_dir"); 91check_bin_file("test.bin", pack("C*", 0x3E, 10)); 92 93$ENV{TEST_ENV} = 'test'; 94 95unlink "test.bin"; 96z80asm('include "test.inc"', '-b "-I${TEST_ENV}_dir"'); 97check_bin_file("test.bin", pack("C*", 0x3E, 10)); 98 99delete $ENV{TEST_ENV}; 100 101unlink "test.bin"; 102z80asm('include "test.inc"', '-b "-Itest${TEST_ENV}_dir"'); 103check_bin_file("test.bin", pack("C*", 0x3E, 10)); 104 105unlink_testfiles(); 106done_testing(); 107