euphoria

changeset 6458:8ba44cdf895c 4.0

* ticket 973: added more tests for setting or disabling warnings at the command line
author Shawn David Pringle B.Sc. <shawn.pringle@gmail.com>
date Sat Apr 14 19:23:29 2018 -0300 (11 days ago)
parents 9a2b4fd1cce0
children 5e907c0b8a39
files tests/t_warning_options.d/dependency.e tests/t_warning_options.d/make_warnings.ex tests/t_warning_options.e
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tests/t_warning_options.d/dependency.e	Sat Apr 14 19:23:29 2018 -0300
     1.3 @@ -0,0 +1,5 @@
     1.4 +foo = 2
     1.5 +global function floor(integer x)
     1.6 +    return x
     1.7 +end function
     1.8 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tests/t_warning_options.d/make_warnings.ex	Sat Apr 14 19:23:29 2018 -0300
     2.3 @@ -0,0 +1,77 @@
     2.4 +-- warning_file( "warnings_issued.txt" )
     2.5 +type boolean(integer x)
     2.6 +    return x = x * x
     2.7 +end type
     2.8 +
     2.9 +global integer foo
    2.10 +-- expect resolution warning here if resolution is enabled {resolution}
    2.11 +include dependency.e
    2.12 +
    2.13 +integer a1 = 1
    2.14 +-- expect short-circut warning here if short-circut is enabled {short_circuit}
    2.15 +function increment_a1()
    2.16 +    a1 += 1
    2.17 +    return a1
    2.18 +end function
    2.19 +
    2.20 +-- do warn here because increment_a1() has a side-effect
    2.21 +if a1 and increment_a1() then
    2.22 +    -- do nothing
    2.23 +end if
    2.24 +
    2.25 +-- do warn here that puts is being overridden {override}
    2.26 +override procedure printf(integer fd, sequence fmt, sequence s)
    2.27 +    --eu:printf(fd, fmt, s)
    2.28 +end procedure
    2.29 +
    2.30 +printf(1, "", {})
    2.31 +
    2.32 +-- warn about builtin_chosen
    2.33 +puts(1, "")
    2.34 +
    2.35 +
    2.36 +procedure bar()
    2.37 +    integer unused = 5
    2.38 +end procedure
    2.39 +
    2.40 +-- war about not_used
    2.41 +bar()
    2.42 +
    2.43 +
    2.44 +-- warn about no_value
    2.45 +procedure baz()
    2.46 +    integer no_value
    2.47 +end procedure
    2.48 +
    2.49 +baz()
    2.50 +
    2.51 +-- warn about useless code {custom}
    2.52 +warning("Useless code")
    2.53 +
    2.54 +
    2.55 +-- {translator} warning must be issued from the command line arguments : An option was given to the translator, but this option is not recognized as valid for the C compiler being used.
    2.56 +
    2.57 +-- {cmdline} is an anachronism
    2.58 +
    2.59 +ifdef not LINUX then
    2.60 +-- {mixed_profile} 
    2.61 +with profile_time
    2.62 +with profile
    2.63 +end ifdef
    2.64 +
    2.65 +switch 4 without fallthru do
    2.66 +    case 0 then
    2.67 +    -- {empty_case}
    2.68 +    case 1 then
    2.69 +       print(1, "one")
    2.70 +    
    2.71 +    -- no case else {default_case}
    2.72 +end switch
    2.73 +
    2.74 +
    2.75 +printf(1, "builtin for floor chosen %d=%d", {floor(2), 2})
    2.76 +
    2.77 +abort(0)
    2.78 +
    2.79 +-- Code {not_reached}
    2.80 +a1 = 1
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tests/t_warning_options.e	Sat Apr 14 19:23:29 2018 -0300
     3.3 @@ -0,0 +1,106 @@
     3.4 +include std/unittest.e
     3.5 +include std/io.e
     3.6 +include std/filesys.e
     3.7 +include std/os.e
     3.8 +include std/regex.e as regex
     3.9 +include std/sequence.e
    3.10 +include std/sort.e
    3.11 +include std/utils.e
    3.12 +include std/text.e
    3.13 +
    3.14 +constant warnings_issued = "warnings_issued.txt"
    3.15 +constant nul = iif(platform() = WINDOWS,"NUL","/dev/null")
    3.16 +
    3.17 +constant warn_regex = regex:new("Warning +{ *([a-z_]+) *}:")
    3.18 +
    3.19 +function warning_parse(sequence file_name)
    3.20 +    sequence warnings = {}
    3.21 +    integer fn = open(file_name, "r")
    3.22 +    object line
    3.23 +    while sequence(line) with entry do
    3.24 +        object results = regex:find(warn_regex, line)
    3.25 +        if sequence(results) then
    3.26 +            sequence warning_string = line[results[2][1]..results[2][2]]
    3.27 +            warnings = append(warnings, warning_string)
    3.28 +        end if
    3.29 +    entry
    3.30 +        line = gets(fn)
    3.31 +    end while
    3.32 +    warnings = sort(warnings)
    3.33 +    integer i = 1
    3.34 +    while i < length(warnings) do
    3.35 +        if equal(warnings[i], warnings[i+1]) then
    3.36 +            warnings = remove(warnings, i)
    3.37 +            continue
    3.38 +        end if
    3.39 +        i += 1
    3.40 +    end while
    3.41 +    return warnings
    3.42 +end function
    3.43 +
    3.44 +constant cl = command_line()
    3.45 +constant eui = cl[1]
    3.46 +
    3.47 +enum M_NORMAL=0, M_STRICT=1
    3.48 +
    3.49 +enum M_ALL=1, M_DEFAULT=3, M_NONE=5   
    3.50 +
    3.51 +enum P_NAME, P_PARAM, P_WARNINGS
    3.52 +
    3.53 +constant 
    3.54 +       configs = { 
    3.55 +       -- M_ALL
    3.56 +       {"all", "-w all", sort({"resolution", "short_circuit", "translator", "override", "builtin_chosen", "not_used", "no_value", "custom", "not_reached", "mixed_profile", "empty_case", "default_case"})},
    3.57 +       -- M_ALL + M_STRICT
    3.58 +       {"all+strict", "-w all -strict", sort({"resolution", "short_circuit", "translator", "override", "builtin_chosen", "not_used", "no_value", "custom", "not_reached", "mixed_profile", "empty_case", "default_case"})},
    3.59 +       -- M_DEFAULT,
    3.60 +       {"normal", "", sort({"resolution", "override", "translator", "builtin_chosen", "custom", "not_reached", "mixed_profile"})},
    3.61 +       -- M_DEFAULT + M_STRICT
    3.62 +       {"strict", "-strict", sort({"resolution", "short_circuit", "translator", "override", "builtin_chosen", "not_used", "no_value", "custom", "not_reached", "mixed_profile", "empty_case", "default_case"})},
    3.63 +       -- M_NONE
    3.64 +       {"none", "-x all", {}},
    3.65 +       -- M_NONE + M_STRICT
    3.66 +       {"none+strict", "-x all -strict", sort({"resolution", "short_circuit", "translator", "override", "builtin_chosen", "not_used", "no_value", "custom", "not_reached", "mixed_profile", "empty_case", "default_case"})}
    3.67 +       }
    3.68 +       
    3.69 +       
    3.70 +       
    3.71 +ifdef EUI then
    3.72 +        if find(match("eui", lower(eui)), length(eui)-{2,6}) = 0 then
    3.73 +            test_fail("Interpreter could not be determined.")
    3.74 +        end if
    3.75 +        for j = 1 to length(configs) do
    3.76 +            sequence config = configs[j]
    3.77 +            sequence cwf = config[P_WARNINGS]
    3.78 +
    3.79 +	    sequence cmd = eui & ' ' & config[P_PARAM] & " -batch -wf " & warnings_issued & " t_warning_options.d" & SLASH & "make_warnings.ex > " & nul
    3.80 +        delete_file(warnings_issued)
    3.81 +	    system(cmd,2)
    3.82 +	    sequence wf = {}
    3.83 +		if file_exists(warnings_issued) > 0 then
    3.84 +			wf = warning_parse(warnings_issued)
    3.85 +        end if
    3.86 +        integer ti  = find("translator", wf)
    3.87 +        if ti then
    3.88 +            wf = remove(wf, ti)
    3.89 +        end if
    3.90 +        ti = find("translator", cwf)
    3.91 +        if ti then
    3.92 +            cwf = remove(cwf, ti)
    3.93 +        end if
    3.94 +        
    3.95 +        ifdef LINUX then
    3.96 +            -- impossible on Linux because with profile_time is an error            
    3.97 +            integer xpi = find("mixed_profile", cwf)
    3.98 +            if xpi then
    3.99 +                cwf = remove(cwf, xpi)
   3.100 +            end if
   3.101 +        end ifdef
   3.102 +        
   3.103 +	    test_equal(config[P_NAME] & " test", join(cwf, ", "), join(wf, ", "))
   3.104 +	end for -- j
   3.105 +
   3.106 +	-- avoid confusion of eutest
   3.107 +	delete_file("ex.err")
   3.108 +end ifdef
   3.109 +test_report()

SCM Home | OpenEuphoria.org Home