Purescript by Example - Issues with Spago, Chapter 2 Getting Started

Hi,
Sorry to start with may be a trivial issue as this is the first time touching Purescript :bowing_man:
Chapter 2 says I need to clone, prepare, and run a test. I cannot even get this far :sob:

https://book.purescript.org/chapter2.html#solving-exercises

% purs --version
0.15.15

% spago --version
0.93.28

To quote:

Now run the tests for this chapter:

cd exercises/chapter2
spago test

It says I should see the tests pass. I don’t:

% cd exercises/chapter2
spago test

Reading Spago workspace configuration...

❌ Couldn't parse Spago config, error:
  Did not find `spago.yaml`. Run `spago init` to initialize a new project.
The configuration file help can be found here https://github.com/purescript/spago#the-configuration-file

I try a hunch:

% spago init
Initializing a new project...
Found PureScript 0.15.15, will use package set 50.11.0
Found existing directory "src", skipping copy of sample sources
Found existing directory "test", skipping copy of sample sources
Found existing file ".gitignore", not overwriting it
Found existing file ".purs-repl", not overwriting it
Set up a new Spago project.
Try running `spago run`

% spago install
Reading Spago workspace configuration...

✅ Selecting package to build: chapter2

Downloading dependencies...
Building...
           Src   Lib   All
Warnings     0     0     0
Errors       0     0     0

✅ Build succeeded.

% spago test   
Reading Spago workspace configuration...

✅ Selecting package to build: chapter2

Downloading dependencies...
Building...
[1/5 ModuleNotFound] src/Euler.purs:4:1

  4  import Data.List (range, filter)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Module Data.List was not found.
  Make sure the source file exists, and that it has been provided as an input to the compiler.

[2/5 ModuleNotFound] src/Euler.purs:5:1

  5  import Data.Foldable (sum)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^

  Module Data.Foldable was not found.
  Make sure the source file exists, and that it has been provided as an input to the compiler.

[3/5 ModuleNotFound] test/Main.purs:7:1

  7  import Test.Unit (suite, test)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Module Test.Unit was not found.
  Make sure the source file exists, and that it has been provided as an input to the compiler.

[4/5 ModuleNotFound] test/Main.purs:8:1

  8  import Test.Unit.Assert as Assert
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Module Test.Unit.Assert was not found.
  Make sure the source file exists, and that it has been provided as an input to the compiler.

[5/5 ModuleNotFound] test/Main.purs:9:1

  9  import Test.Unit.Main (runTest)
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Module Test.Unit.Main was not found.
  Make sure the source file exists, and that it has been provided as an input to the compiler.

           Src   Lib   All
Warnings     0     0     0
Errors       5     0     5

❌ Failed to build.

% cat spago.yaml 
package:
  name: chapter2
  dependencies:
    - console
    - effect
    - prelude
  test:
    main: Test.Main
    dependencies: []
workspace:
  package_set:
    registry: 50.11.0
  extra_packages: {}

 cat spago.dhall 
{-
Welcome to a Spago project!
You can edit this file as you like.
-}
{ name = "my-project"
, dependencies =
  [ "console"
  , "effect"
  , "foldable-traversable"
  , "integers"
  , "lists"
  , "numbers"
  , "prelude"
  , "test-unit"
  ]
, packages = ./packages.dhall
, sources = [ "src/**/*.purs", "test/**/*.purs" ]
}

% git status -s
?? spago.lock
?? spago.yaml

Can someone please tell point me in the right direction for the step I missed? I naively expected this to just work but maybe I screwed up something? Or misunderstand something? It does not seem deps are installed rightly… :confused:

Hi,

the book/example code is still on old spago (where you have .dhal files instead of the spago.yml.

So either switch back to spago:0.21.0 (should be latest as well) or try and convert it (see the explanation here)

1 Like

Ah! Makes sense. I started to sense this but now I think I understand. I will try this again as you suggest. Thank you