From ad3705de70d53ef0602e63c5f3d2f5317d75aa62 Mon Sep 17 00:00:00 2001 From: "Andres G. Aragoneses" Date: Fri, 18 Aug 2023 19:23:34 +0800 Subject: [PATCH] scripts/runTests.fsx: acceptance test for warning --- scripts/runTests.fsx | 49 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/scripts/runTests.fsx b/scripts/runTests.fsx index 102ccd4a..1c052f33 100755 --- a/scripts/runTests.fsx +++ b/scripts/runTests.fsx @@ -331,3 +331,52 @@ let legacyDefineTest = Process.Execute(CreateCommand(legacyDefineTest, String.Empty), Echo.All) |> UnwrapDefault + + +let contentOfScriptWithWarning = + """#!/usr/bin/env fsx + +let GiveMeBool() : bool = + false + +GiveMeBool() +printf "hello" +""" + +let warningTest = Path.Combine(TestDir.FullName, "testWarning.fsx") |> FileInfo +File.WriteAllText(warningTest.FullName, contentOfScriptWithWarning) + +match Misc.GuessPlatform() with +| Misc.Platform.Windows -> () +| _ -> + Process + .Execute( + { + Command = "chmod" + Arguments = sprintf "+x %s" warningTest.FullName + }, + Echo.All + ) + .UnwrapDefault() + |> ignore + +let currentDir = Directory.GetCurrentDirectory() + +let possibleDirBuildProps = + Path.Combine(currentDir, "Directory.Build.props") |> FileInfo + +if possibleDirBuildProps.Exists then + // this file could alter the behaviour of fsxc when compiling, making the result of the test be misleading + possibleDirBuildProps.Delete() + +let warningAsErrorProc = + Process.Execute(CreateCommand(warningTest, String.Empty), Echo.All) + +match warningAsErrorProc.Result with +| Error _ -> + // warning as error worked! + () +| _ -> + failwithf + "Should have failed to compile/execute %s because warnings as errors" + warningTest.Name