1
- using Pine ;
1
+ using Mono . Unix ;
2
+ using Pine ;
2
3
using System . Collections . Generic ;
3
4
using System . Collections . Immutable ;
5
+ using System . IO ;
4
6
using System . Linq ;
5
7
using System . Runtime . InteropServices ;
6
8
@@ -29,11 +31,25 @@ public class ElmTestRs
29
31
( "98708c4ecd1a34b61545f0faca7ac3c46b5bb3d0bf6b4719b16eb4cffe0a82ac" ,
30
32
@"https://github.com/mpizenberg/elm-test-rs/releases/download/v1.2.2/elm-test-rs_windows.zip" ) ) ;
31
33
32
- static public byte [ ] LoadElmTestRsExecutableFileForCurrentOs ( )
34
+ static public IReadOnlyDictionary < OSPlatform , ( string hash , string remoteSource ) > DenoExecutableFileByOs =
35
+ ImmutableDictionary < OSPlatform , ( string hash , string remoteSource ) > . Empty
36
+ . Add (
37
+ OSPlatform . Linux ,
38
+ ( "34374d77515b093028df6605b6e74985aa6cd7a022c5e8310a14d65daecbd91d" ,
39
+ @"https://github.com/denoland/deno/releases/download/v1.16.2/deno-x86_64-unknown-linux-gnu.zip" ) )
40
+ . Add (
41
+ OSPlatform . Windows ,
42
+ ( "3a1611329306d24b24fd6b98418ddec9ee79c044623e712093db24eba6a573df" ,
43
+ @"https://github.com/denoland/deno/releases/download/v1.16.2/deno-x86_64-pc-windows-msvc.zip" ) ) ;
44
+
45
+ static public byte [ ] ElmTestRsExecutableFileForCurrentOs ( ) => LoadFileForCurrentOs ( ElmTestRsExecutableFileByOs ) ;
46
+
47
+ static public byte [ ] DenoExecutableFileForCurrentOs ( ) => LoadFileForCurrentOs ( DenoExecutableFileByOs ) ;
48
+
49
+ static public byte [ ] LoadFileForCurrentOs ( IReadOnlyDictionary < OSPlatform , ( string hash , string remoteSource ) > dict )
33
50
{
34
51
var hashAndRemoteSource =
35
- ElmTestRsExecutableFileByOs
36
- . FirstOrDefault ( c => RuntimeInformation . IsOSPlatform ( c . Key ) ) . Value ;
52
+ dict . FirstOrDefault ( c => RuntimeInformation . IsOSPlatform ( c . Key ) ) . Value ;
37
53
38
54
if ( hashAndRemoteSource . hash == null )
39
55
throw new System . Exception ( "Unknown OS: " + RuntimeInformation . OSDescription ) ;
@@ -48,22 +64,61 @@ static public byte[] LoadElmTestRsExecutableFileForCurrentOs()
48
64
static public ( string stdout , string stderr , IReadOnlyList < ( string rawLine , ElmTestRsReportJsonEntry parsedLine ) > stdoutLines ) Run (
49
65
IImmutableDictionary < IImmutableList < string > , IReadOnlyList < byte > > elmProjectFiles )
50
66
{
51
- var elmTestExecutableFile = LoadElmTestRsExecutableFileForCurrentOs ( ) ;
67
+ var elmTestExecutableFile = ElmTestRsExecutableFileForCurrentOs ( ) ;
52
68
53
69
var elmExecutableFileName = "elm.exe" ;
54
70
71
+ string elmTestEnvironmentPath = null ;
72
+
73
+ {
74
+ /*
75
+ * We found no way yet to point elm-test-rs to the deno executable file.
76
+ * As a temporary solution, adapt the file path and environment variables to help elm-test-rs find it.
77
+ * */
78
+
79
+ var ( denoExecutableFileName , pathEnvironmentVarSeparator ) =
80
+ RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ? ( "deno.exe" , ";" ) : ( "deno" , ":" ) ;
81
+
82
+ var denoExecutableFileContent = DenoExecutableFileForCurrentOs ( ) ;
83
+
84
+ var denoExecutableFileDirectory =
85
+ Path . Combine ( Filesystem . CacheDirectory ,
86
+ "bin-by-sha256" ,
87
+ CommonConversion . StringBase16FromByteArray ( CommonConversion . HashSHA256 ( denoExecutableFileContent ) ) ) ;
88
+
89
+ var denoExecutableFilePath = Path . Combine ( denoExecutableFileDirectory , denoExecutableFileName ) ;
90
+
91
+ Directory . CreateDirectory ( denoExecutableFileDirectory ) ;
92
+
93
+ File . WriteAllBytes ( denoExecutableFilePath , denoExecutableFileContent ) ;
94
+
95
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Linux ) )
96
+ {
97
+ var unixFileInfo = new UnixFileInfo ( denoExecutableFilePath ) ;
98
+
99
+ unixFileInfo . FileAccessPermissions |=
100
+ FileAccessPermissions . GroupExecute | FileAccessPermissions . UserExecute | FileAccessPermissions . OtherExecute |
101
+ FileAccessPermissions . GroupRead | FileAccessPermissions . UserRead | FileAccessPermissions . OtherRead ;
102
+ }
103
+
104
+ var environmentPath =
105
+ System . Environment . GetEnvironmentVariable ( "PATH" ) ?? System . Environment . GetEnvironmentVariable ( "path" ) ;
106
+
107
+ elmTestEnvironmentPath = environmentPath + pathEnvironmentVarSeparator + denoExecutableFileDirectory ;
108
+ }
109
+
55
110
var environmentFilesExecutable =
56
- ImmutableDictionary . Create < IImmutableList < string > , IReadOnlyList < byte > > ( ) . SetItem (
57
- ImmutableList . Create ( elmExecutableFileName ) , ElmFullstack . ProcessFromElm019Code . GetElmExecutableFile ) ;
111
+ ImmutableDictionary . Create < IImmutableList < string > , IReadOnlyList < byte > > ( )
112
+ . SetItem ( ImmutableList . Create ( elmExecutableFileName ) , ElmFullstack . ProcessFromElm019Code . GetElmExecutableFile ) ;
58
113
59
114
var executeElmTestResult =
60
115
ExecutableFile . ExecuteFileWithArguments (
61
116
environmentFilesNotExecutable : elmProjectFiles ,
62
117
executableFile : elmTestExecutableFile ,
63
- arguments : "--compiler=./" + elmExecutableFileName + " --report=json" ,
64
- environmentStrings : null ,
118
+ arguments : "--compiler=./" + elmExecutableFileName + " --deno --report=json" ,
119
+ environmentStrings : ImmutableDictionary < string , string > . Empty . SetItem ( "PATH" , elmTestEnvironmentPath ) ,
65
120
workingDirectory : null ,
66
- environmentFilesExecutable : environmentFilesExecutable ) ;
121
+ environmentFilesExecutable : environmentFilesExecutable ) ; ;
67
122
68
123
var stdoutLines =
69
124
executeElmTestResult . processOutput . StandardOutput
0 commit comments