Pudu programming language
Menu
Package

@chrismichaelps / pudu-lang-environment

Environment files for Pudu: load .env variables safely with layered files, discovery, expansion, typed reads, and secrets kept out of every message

0.1.0Apache-2.01

InstallClose

PuduLangEnvironmentTest.pudu

Pudu39 lines2.0 KB

GitHub ↗
1/** @Test.Root.Suite — problems and their descriptions */2module PuduLangEnvironmentTest34import Std.Io as Io5import Std.Test as Test6import PuduLangEnvironment as Environment78/// Runs the suite.9fn main() -> Int {10  let problems = [11    Environment.BlankPath, Environment.MissingFile(".env"), Environment.Unreadable("a.env", "denied"),12    Environment.Undecodable("b.env", "UTF-8"), Environment.UnclosedQuote(".env", 3, "KEY"),13    Environment.NotFound(["/a/.env", "/.env"]), Environment.UnsafeEnvironmentName("../x"),14    Environment.InvalidOptions(["one", "two"]), Environment.Missing(["A", "B"]), Environment.Malformed("PORT", "a whole number"),15    Environment.Invalid(["port (GreaterThanValidator)", "url (NotEmptyValidator)"])16  ]17  let checks = Test.suite("Environment", &[18      Test.equals("every problem is described", &problems.map(|problem: Environment.Problem| Environment.describe(&problem)), &[19          "An environment file path is blank.",20          "The environment file '.env' does not exist.",21          "The environment file 'a.env' could not be read: denied",22          "The environment source 'b.env' is not valid UTF-8.",23          "The value of 'KEY' in '.env' opens a quote on line 3 that is never closed.",24          "No environment file was found among: /a/.env, /.env",25          "The environment name '../x' is blank or holds a path separator, '..', or a character a file name cannot hold.",26          "The environment options are invalid: one; two",27          "No value is set for: A, B",28          "The value of 'PORT' is not a whole number.",29          "The settings are invalid: port (GreaterThanValidator), url (NotEmptyValidator)"30        ]),31      Test.equals("only absent or unreadable sources are skippable", &problems.map(|problem: Environment.Problem| Environment.isSkippable(&problem)), &[true, true, true, true, false, true, false, false, false, false, false])32    ])33  let ran = Test.run(&checks)34  for failure in Test.failuresOf(&ran) {35    let _reported = Io.writeErrorLine(failure)36  }37  Test.report(&ran)38}39