I test nel track ReScript

Scopri come testare i tuoi esercizi ReScript su Exercism


Scaricare un esercizio

Usa la CLI di Exercism per scaricare l'esercizio su cui vuoi lavorare.

exercism download --track=rescript --exercise=hello-world

Poi entra nella directory dell'esercizio.

cd /path/to/exercism/rescript/hello-world

Installare le dipendenze

Prima di eseguire i test, installa le dipendenze dell'esercizio.

npm install

Eseguire i test

Compila ed esegui la suite di test fornita usando exercism test oppure npm run test.

Capire i risultati dei test

Il test runner mostra ogni esecuzione dei test con lo stato di superato o non superato.

1/3: no name given
  PASS - no name given
2/3: a name given
  FAIL - a name given
    ---
    operator: equal
    left:  One for you, one for me.
    right: One for Alice, one for me.
    ...
3/3: another name given
  FAIL - another name given
    ---
    operator: equal
    left:  One for you, one for me.
    right: One for Bob, one for me.
    ...

# Ran 3 tests (3 assertions)
# 1 passed
# 2 failed

left è ciò che ha restituito il codice. right è ciò che il test si aspettava.

Capire la struttura dell'esercizio

two-fer/
├── src/
│   ├── TwoFer.res   // your solution goes here
│   └── TwoFer.resi  // the optional interface file containing signatures
├── tests/
│   └── TwoFer_test.res // your test suite
├── package.json // used to install project dependencies
└── ...

Qui TwoFer.resi è un file di interfaccia facoltativo. Quando è presente, definisce le firme delle funzioni che la soluzione deve rispettare e può servire da suggerimento su cosa implementare.

Per esempio, se l'interfaccia dichiara:

let hello: unit => string

L'implementazione dovrebbe definire:

let hello = () => "Hello, World!"

Errori del compilatore

Se il codice non compila, il compilatore di ReScript produce messaggi di errore dettagliati con la posizione esatta e i tipi attesi.

  We've found a bug for you!

  1 │ let x: string = 42

  This has type: int
  But it's expected to have type: string

  You can convert int to string with Int.toString.

Leggi il messaggio di errore con attenzione: di solito indica direttamente il problema.