Play

Check-in [a49b84525d]
Login
Overview
Comment:Add tests to check that only relevant packages are resolved. Currently fails.
Timelines: family | ancestors | descendants | both | modules
Files: files | file ages | folders
SHA3-256: a49b84525d5c238968a84ab1ec807cee89098599b9ba7a804abb0df077cd7cdf
User & Date: robin.hansen on 2021-02-28 11:39:26
Other Links: branch diff | manifest | tags
Context
2021-03-14
10:14
Only load highest versioned packages, and don't load packages which aren't actual dependencies. check-in: 4b3906674f user: robin.hansen tags: modules
2021-02-28
11:39
Add tests to check that only relevant packages are resolved. Currently fails. check-in: a49b84525d user: robin.hansen tags: modules
2021-02-27
15:58
Strip .play suffix from files before trying to convert to a ModuleName. check-in: 03c71127f3 user: robin.hansen tags: modules
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Modified tests/Test/PackageLoader.elm from [7f4459b9a4] to [9aebcd3249].

18
19
20
21
22
23
24



25
26

27
28
29
30
31
32
33
..
36
37
38
39
40
41
42




43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97




















98
99
100
101
102
103
104
...
125
126
127
128
129
130
131
132

133
134
135
136
137
138
139
...
146
147
148
149
150
151
152
153
154
155

156
157

158
159
160
161
162
163
164
165
166
167








168


























































        , test "Retrieves necessary files" <|
            \_ ->
                PackageLoader.init "/project"
                    |> expectSideEffects testFiles
                        [ PackageLoader.ReadFile "/project" "play.json"
                        , PackageLoader.ResolveDirectories "/project/lib"
                        , PackageLoader.ReadFile "/project/lib/template_strings" "play.json"



                        , PackageLoader.ResolvePackageModules "robheghan/fnv" "/project"
                        , PackageLoader.ResolvePackageModules "jarvis/template_strings" "/project/lib/template_strings"

                        ]
        ]


expectSideEffects : Dict String String -> List PackageLoader.SideEffect -> PackageLoader.Model -> Expectation
expectSideEffects fileSystem expectedSFs model =
    case getSideEffect model of
................................................................................
                PackageLoader.Done _ ->
                    Expect.equalLists [] expectedSFs

                _ ->
                    Expect.fail <| "Expected model be Done, was: " ++ Debug.toString model

        Just sideEffect ->




            case sideEffect of
                PackageLoader.ReadFile path filename ->
                    case Dict.get (path ++ "/" ++ filename) fileSystem of
                        Just fileContent ->
                            expectSideEffects
                                fileSystem
                                (List.remove sideEffect expectedSFs)
                                (PackageLoader.update
                                    (PackageLoader.FileContents path filename fileContent)
                                    model
                                )

                        Nothing ->
                            Expect.fail <| "No such file: " ++ path

                PackageLoader.ResolveDirectories dir ->
                    let
                        childPaths =
                            Dict.keys fileSystem
                                |> List.filter
                                    (\path ->
                                        String.startsWith dir path
                                            && String.endsWith "play.json" path
                                    )
                                |> List.map (String.replace "/play.json" "")
                                |> List.map PackagePath.Directory
                    in
                    expectSideEffects
                        fileSystem
                        (List.remove sideEffect expectedSFs)
                        (PackageLoader.update
                            (PackageLoader.ResolvedDirectories dir childPaths)
                            model
                        )

                PackageLoader.ResolvePackageModules packageName packagePath ->
                    let
                        srcPath =
                            packagePath ++ "/src/"

                        childPaths =
                            Dict.keys fileSystem
                                |> List.filter
                                    (\path ->
                                        String.startsWith srcPath path
                                    )
                                |> List.map (String.replace srcPath "")
                    in
                    expectSideEffects
                        fileSystem
                        (List.remove sideEffect expectedSFs)
                        (PackageLoader.update
                            (PackageLoader.ResolvedPackageModules packageName childPaths)
                            model
                        )






















getSideEffect : PackageLoader.Model -> Maybe PackageLoader.SideEffect
getSideEffect model =
    case model of
        PackageLoader.Done _ ->
            Nothing
................................................................................
                "name": "robheghan/fnv",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "fnv"
                ],
                "dependencies": {
                    "jarvis/template_strings": "1.2.0"

                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
        , ( "/project/lib/template_strings/play.json"
          , """
            {
                "name": "jarvis/template_strings",
                "version": "1.2.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "template_strings"
                ],
                "dependencies": {

                },
                "package-paths": [

                ]
            }
          """
          )
        , ( "/project/lib/template_strings/src/template_strings/mod.play"
          , """
            def: dec
            : 1 =
            """
          )








        ]

































































>
>
>


>







 







>
>
>
>
|
|
|
|
|
|
|
|
|
|
|

|
|

|
|
|
|
|
<
<
<
<
|
|
|
|
|
|
|
|
|
|

|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







 







|
>







 







|


>


>










>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
..
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70




71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
...
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
...
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
        , test "Retrieves necessary files" <|
            \_ ->
                PackageLoader.init "/project"
                    |> expectSideEffects testFiles
                        [ PackageLoader.ReadFile "/project" "play.json"
                        , PackageLoader.ResolveDirectories "/project/lib"
                        , PackageLoader.ReadFile "/project/lib/template_strings" "play.json"
                        , PackageLoader.ReadFile "/project/lib/template_strings/lib/version" "play.json"
                        , PackageLoader.ReadFile "/project/lib/unused" "play.json"
                        , PackageLoader.ReadFile "/project/lib/version" "play.json"
                        , PackageLoader.ResolvePackageModules "robheghan/fnv" "/project"
                        , PackageLoader.ResolvePackageModules "jarvis/template_strings" "/project/lib/template_strings"
                        , PackageLoader.ResolvePackageModules "play/version" "/project/lib/template_strings/lib/version"
                        ]
        ]


expectSideEffects : Dict String String -> List PackageLoader.SideEffect -> PackageLoader.Model -> Expectation
expectSideEffects fileSystem expectedSFs model =
    case getSideEffect model of
................................................................................
                PackageLoader.Done _ ->
                    Expect.equalLists [] expectedSFs

                _ ->
                    Expect.fail <| "Expected model be Done, was: " ++ Debug.toString model

        Just sideEffect ->
            if not <| List.member sideEffect expectedSFs then
                Expect.fail <| "Unexpected side effect: " ++ Debug.toString sideEffect

            else
                case sideEffect of
                    PackageLoader.ReadFile path filename ->
                        case Dict.get (path ++ "/" ++ filename) fileSystem of
                            Just fileContent ->
                                expectSideEffects
                                    fileSystem
                                    (List.remove sideEffect expectedSFs)
                                    (PackageLoader.update
                                        (PackageLoader.FileContents path filename fileContent)
                                        model
                                    )

                            Nothing ->
                                Expect.fail <| "No such file: " ++ path

                    PackageLoader.ResolveDirectories dir ->
                        let
                            childPaths =
                                Dict.keys fileSystem
                                    |> List.filter (childPackage dir)




                                    |> List.map (String.replace "/play.json" "")
                                    |> List.map PackagePath.Directory
                        in
                        expectSideEffects
                            fileSystem
                            (List.remove sideEffect expectedSFs)
                            (PackageLoader.update
                                (PackageLoader.ResolvedDirectories dir childPaths)
                                model
                            )

                    PackageLoader.ResolvePackageModules packageName packagePath ->
                        let
                            srcPath =
                                packagePath ++ "/src/"

                            childPaths =
                                Dict.keys fileSystem
                                    |> List.filter
                                        (\path ->
                                            String.startsWith srcPath path
                                        )
                                    |> List.map (String.replace srcPath "")
                        in
                        expectSideEffects
                            fileSystem
                            (List.remove sideEffect expectedSFs)
                            (PackageLoader.update
                                (PackageLoader.ResolvedPackageModules packageName childPaths)
                                model
                            )


childPackage : String -> String -> Bool
childPackage targetDir path =
    if not <| String.startsWith targetDir path then
        False

    else
        let
            pathParts =
                path
                    |> String.replace (targetDir ++ "/") ""
                    |> String.split "/"
        in
        case pathParts of
            [ _, "play.json" ] ->
                True

            _ ->
                False


getSideEffect : PackageLoader.Model -> Maybe PackageLoader.SideEffect
getSideEffect model =
    case model of
        PackageLoader.Done _ ->
            Nothing
................................................................................
                "name": "robheghan/fnv",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "fnv"
                ],
                "dependencies": {
                    "jarvis/template_strings": "1.2.0",
                    "play/version": "1.0.0"
                },
                "package-paths": [
                    "lib/*"
                ]
            }
            """
          )
................................................................................
        , ( "/project/lib/template_strings/play.json"
          , """
            {
                "name": "jarvis/template_strings",
                "version": "1.2.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "template_strings/mod"
                ],
                "dependencies": {
                    "play/version": "1.1.0"
                },
                "package-paths": [
                    "lib/version"
                ]
            }
          """
          )
        , ( "/project/lib/template_strings/src/template_strings/mod.play"
          , """
            def: dec
            : 1 =
            """
          )
        , ( "/project/lib/unused/play.json"
          , """
            {
                "name": "some/useless",
                "version": "1.7.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "useless/mod"
                ],
                "dependencies": {
                },
                "package-paths": [
                ]
            }
          """
          )
        , ( "/project/lib/unused/src/useless/mod.play"
          , """
            def: square
            : dup *
            """
          )
        , ( "/project/lib/version/play.json"
          , """
            {
                "name": "play/version",
                "version": "1.0.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "version/data"
                ],
                "dependencies": {
                },
                "package-paths": [
                ]
            }
          """
          )
        , ( "/project/lib/version/src/version/data.play"
          , """
            def: version
            : 1
            """
          )
        , ( "/project/lib/template_strings/lib/version/play.json"
          , """
            {
                "name": "play/version",
                "version": "1.2.0",
                "language-version": "0.2.0",
                "exposed-modules": [
                    "version/data"
                ],
                "dependencies": {
                },
                "package-paths": [
                ]
            }
          """
          )
        , ( "/project/lib/template_strings/lib/version/src/version/data.play"
          , """
            def: version
            : 2
            """
          )
        ]