Le prove avviano il sito di prova solo da SyntheticSite, che legge il seme da FEBE_SEME_PROVA e usa 13 quando manca: senza la variabile non cambia nulla. Le classi che lo avviano stanno nella categoria SitoDiProva, così la CI può rifarle con un seme diverso a ogni esecuzione senza raddoppiare tutta la suite, e il seme finisce nell'output della prova per rifare un errore. Nuove prove senza browser: la forma del mondo su cui contano le prove d'insieme vale per 300 semi, i lettori leggono pagina dopo pagina ciò che il sito serve con il seme dell'esecuzione, e nessuna prova avvia il sito per altre vie o resta fuori dalla categoria. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
47 lines
2.2 KiB
C#
47 lines
2.2 KiB
C#
using System.Globalization;
|
|
using Febe.SitoDiProva;
|
|
|
|
namespace Febe.Tests.Support;
|
|
|
|
/// <summary>
|
|
/// The one way the tests start the local test site (spec §14.2), so that a run can choose the seed of its synthetic
|
|
/// world: <see cref="Variable"/> when it is set, <see cref="DefaultSeed"/> otherwise (nothing changes when it is unset).
|
|
/// The CI runs the whole suite with the default seed, then the tests of <see cref="Category"/> again with a seed of
|
|
/// its own that it prints in the log: a failure is reproduced by setting the same variable.
|
|
/// </summary>
|
|
internal static class SyntheticSite
|
|
{
|
|
/// <summary>Environment variable with the seed of the synthetic world.</summary>
|
|
public const string Variable = "FEBE_SEME_PROVA";
|
|
|
|
/// <summary>The seed when the variable is not set: the one of the command-line site and of the cleaned samples.</summary>
|
|
public const int DefaultSeed = 13;
|
|
|
|
/// <summary>Test category of the tests whose world comes from the seed (the CI runs them with a second seed).</summary>
|
|
public const string Category = "SitoDiProva";
|
|
|
|
/// <summary>The seed of this run.</summary>
|
|
public static int Seed => ParseSeed(Environment.GetEnvironmentVariable(Variable));
|
|
|
|
/// <summary>Starts the test site with the seed of this run, and says which one in the output of the test.</summary>
|
|
public static Task<TestSite> StartAsync()
|
|
{
|
|
var seed = Seed;
|
|
Console.WriteLine($"Sito di prova con il seme {seed.ToString(CultureInfo.InvariantCulture)} (si cambia con {Variable}).");
|
|
return TestSite.StartAsync(new TestSiteOptions { Seed = seed });
|
|
}
|
|
|
|
/// <summary>The seed written in <paramref name="value"/>: the default when it is empty, an error when it is not a number.</summary>
|
|
public static int ParseSeed(string? value)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(value))
|
|
{
|
|
return DefaultSeed;
|
|
}
|
|
|
|
return int.TryParse(value.Trim(), NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out var seed)
|
|
? seed
|
|
: throw new InvalidOperationException($"{Variable} deve essere un numero intero (fra -2147483648 e 2147483647), non «{value}».");
|
|
}
|
|
}
|