From f5e46c9bf2f50d66a953fa133161fc829cecff06 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Sat, 10 Feb 2024 13:22:13 -0700 Subject: chore: move cli/tests/ -> tests/ (#22369) This looks like a massive PR, but it's only a move from cli/tests -> tests, and updates of relative paths for files. This is the first step towards aggregate all of the integration test files under tests/, which will lead to a set of integration tests that can run without the CLI binary being built. While we could leave these tests under `cli`, it would require us to keep a more complex directory structure for the various test runners. In addition, we have a lot of complexity to ignore various test files in the `cli` project itself (cargo publish exclusion rules, autotests = false, etc). And finally, the `tests/` folder will eventually house the `test_ffi`, `test_napi` and other testing code, reducing the size of the root repo directory. For easier review, the extremely large and noisy "move" is in the first commit (with no changes -- just a move), while the remainder of the changes to actual files is in the second commit. --- cli/tests/testdata/assets/DenoWinRunner.cs | 127 --------------------- cli/tests/testdata/assets/DenoWinRunner.ps1 | 10 -- .../testdata/assets/deno_dom_0.1.3-alpha2.wasm | Bin 616631 -> 0 bytes cli/tests/testdata/assets/fixture.json | 14 --- cli/tests/testdata/assets/hello.txt | 1 - cli/tests/testdata/assets/lock_target.txt | 1 - cli/tests/testdata/assets/unreachable.wasm | Bin 42 -> 0 bytes 7 files changed, 153 deletions(-) delete mode 100644 cli/tests/testdata/assets/DenoWinRunner.cs delete mode 100644 cli/tests/testdata/assets/DenoWinRunner.ps1 delete mode 100644 cli/tests/testdata/assets/deno_dom_0.1.3-alpha2.wasm delete mode 100644 cli/tests/testdata/assets/fixture.json delete mode 100644 cli/tests/testdata/assets/hello.txt delete mode 100644 cli/tests/testdata/assets/lock_target.txt delete mode 100644 cli/tests/testdata/assets/unreachable.wasm (limited to 'cli/tests/testdata/assets') diff --git a/cli/tests/testdata/assets/DenoWinRunner.cs b/cli/tests/testdata/assets/DenoWinRunner.cs deleted file mode 100644 index 2f9e9f89f..000000000 --- a/cli/tests/testdata/assets/DenoWinRunner.cs +++ /dev/null @@ -1,127 +0,0 @@ -using System; -using System.ComponentModel; -using System.Diagnostics; -using System.IO; -using System.Runtime.InteropServices; -using System.Threading.Tasks; - -[Flags] -public enum DenoConstraints : int -{ - None = 0, - NoStdin = 1, - NoStdout = 2, - NoStderr = 4 -} - -public class DenoWinRunner -{ - private const int STD_INPUT_HANDLE = -10; - private const int STD_OUTPUT_HANDLE = -11; - private const int STD_ERROR_HANDLE = -12; - - private const int FILE_NOT_FOUND = 2; - private const int WAIT_TIMEOUT = 258; - - [DllImport("kernel32.dll")] - private static extern void SetStdHandle(int nStdHandle, IntPtr handle); - - /// - /// Runs Deno.exe under the specified constraints - /// - /// Path to the Deno.exe file. Can be absolute or relative - /// Path to the script file Deno should run. - /// The constraints to apply to the Deno process - /// How long to wait for the Deno process to exit - /// The deno.exe exit code, or an exit code provided by the test runner - public static int RunDenoScript(string pathToDenoExe, string pathToTestScript, DenoConstraints constraints, uint timeoutMilliseconds = 1000) - { - try - { - if (!File.Exists(pathToDenoExe)) - { - Console.Error.WriteLine("Cannot find Deno.exe at " + pathToDenoExe); - return FILE_NOT_FOUND; - } - - if (!File.Exists(pathToTestScript)) - { - Console.Error.WriteLine("Cannot find test script at " + pathToTestScript); - return FILE_NOT_FOUND; - } - - ProcessStartInfo startInfo = new ProcessStartInfo(pathToDenoExe) - { - ErrorDialog = false, - UseShellExecute = false, - Arguments = @"run -A " + pathToTestScript, - RedirectStandardInput = !constraints.HasFlag(DenoConstraints.NoStdin), - RedirectStandardOutput = !constraints.HasFlag(DenoConstraints.NoStdout), - RedirectStandardError = !constraints.HasFlag(DenoConstraints.NoStderr) - }; - - startInfo.Environment.Add("RUST_BACKTRACE", "1"); - - if (constraints.HasFlag(DenoConstraints.NoStdin)) - { - SetStdHandle(STD_INPUT_HANDLE, (IntPtr)null); - } - - if (constraints.HasFlag(DenoConstraints.NoStdout)) - { - SetStdHandle(STD_OUTPUT_HANDLE, (IntPtr)null); - } - - if (constraints.HasFlag(DenoConstraints.NoStderr)) - { - SetStdHandle(STD_ERROR_HANDLE, (IntPtr)null); - } - - Process process = new Process { StartInfo = startInfo }; - process.Start(); - - Task stdErrTask = startInfo.RedirectStandardError ? - process.StandardError.ReadToEndAsync() : Task.FromResult(null); - Task stdOutTask = startInfo.RedirectStandardOutput ? - process.StandardOutput.ReadToEndAsync() : Task.FromResult(null); - - if (!process.WaitForExit((int)timeoutMilliseconds)) - { - Console.Error.WriteLine("Timed out waiting for Deno process to exit"); - try - { - process.Kill(); - } - catch - { - // Kill might fail, either because the process already exited or due to some other error - Console.Error.WriteLine("Failure killing the Deno process - possible Zombie Deno.exe process"); - } - return WAIT_TIMEOUT; - } - - // If the Deno process wrote to STDERR - append it to our STDERR - if (!constraints.HasFlag(DenoConstraints.NoStderr)) - { - string error = stdErrTask.Result; - if (!string.IsNullOrWhiteSpace(error)) - { - Console.Error.WriteLine(error); - } - } - - return process.ExitCode; - - } - catch (Win32Exception ex) - { - Console.Error.WriteLine("Win32Exception: code = " + ex.ErrorCode + ", message: " + ex.Message); - return ex.NativeErrorCode; - } - catch (Exception ex) - { - Console.Error.WriteLine("Exception: message: " + ex.Message); - return -1; - } - } -} diff --git a/cli/tests/testdata/assets/DenoWinRunner.ps1 b/cli/tests/testdata/assets/DenoWinRunner.ps1 deleted file mode 100644 index 203b5d36c..000000000 --- a/cli/tests/testdata/assets/DenoWinRunner.ps1 +++ /dev/null @@ -1,10 +0,0 @@ -$Source = [IO.File]::ReadAllText("$PSScriptRoot\DenoWinRunner.cs") -$denoExePath = $args[0] -$scriptPath = $args[1] -$constraints = $args[2] -$timeout = 5000; -Add-Type -TypeDefinition $Source -Language CSharp -Write-Output("Running Deno script: " + $args[1]) -$code = [DenoWinRunner]::RunDenoScript($denoExePath, $scriptPath, $constraints, $timeout) -Write-Output("Deno.exe or the test wrapper has exited with code: $code") -exit $code diff --git a/cli/tests/testdata/assets/deno_dom_0.1.3-alpha2.wasm b/cli/tests/testdata/assets/deno_dom_0.1.3-alpha2.wasm deleted file mode 100644 index 6dd9d0e91..000000000 Binary files a/cli/tests/testdata/assets/deno_dom_0.1.3-alpha2.wasm and /dev/null differ diff --git a/cli/tests/testdata/assets/fixture.json b/cli/tests/testdata/assets/fixture.json deleted file mode 100644 index 56e056b6a..000000000 --- a/cli/tests/testdata/assets/fixture.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "name": "deno", - "private": true, - "devDependencies": { - "@types/prettier": "1.16.1", - "@typescript-eslint/eslint-plugin": "2.5.0", - "@typescript-eslint/parser": "2.5.0", - "eslint": "5.15.1", - "eslint-config-prettier": "4.1.0", - "magic-string": "0.25.2", - "prettier": "1.17.1", - "typescript": "3.6.3" - } -} diff --git a/cli/tests/testdata/assets/hello.txt b/cli/tests/testdata/assets/hello.txt deleted file mode 100644 index 6769dd60b..000000000 --- a/cli/tests/testdata/assets/hello.txt +++ /dev/null @@ -1 +0,0 @@ -Hello world! \ No newline at end of file diff --git a/cli/tests/testdata/assets/lock_target.txt b/cli/tests/testdata/assets/lock_target.txt deleted file mode 100644 index 5a29d1c26..000000000 --- a/cli/tests/testdata/assets/lock_target.txt +++ /dev/null @@ -1 +0,0 @@ -This file is used for file locking tests and should not be used for anything else. \ No newline at end of file diff --git a/cli/tests/testdata/assets/unreachable.wasm b/cli/tests/testdata/assets/unreachable.wasm deleted file mode 100644 index a4110ee39..000000000 Binary files a/cli/tests/testdata/assets/unreachable.wasm and /dev/null differ -- cgit v1.2.3