Skip to content

Commit

Permalink
Migrates all unit tests to Rely
Browse files Browse the repository at this point in the history
  • Loading branch information
ManasJayanth committed Dec 24, 2019
1 parent 4b27832 commit 58db380
Show file tree
Hide file tree
Showing 28 changed files with 1,301 additions and 906 deletions.
2 changes: 2 additions & 0 deletions .ci/build-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
displayName: "esy build"
- script: "esy npm-release"
displayName: "esy npm-release"
- script: "esy test"
displayName: "Running unit tests"
- ${{ if eq(parameters.platform, 'Windows') }}:
- script: mkdir $(System.DefaultWorkingDirectory)\..\tests-tmp-dir
displayName: 'Creating temporary workspace for tests'
Expand Down
324 changes: 161 additions & 163 deletions bin/Pesy.re
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module Lib = PesyEsyPesyLib.Lib;
module Utils = PesyEsyPesyUtils.Utils;
open Lib;
open Utils;
open Printf;
open EsyCommand;
open Cmdliner;
open PesyEsyPesyErrors.Errors;

exception BootstrappingError(string);
exception LsLibsError(string);
Expand All @@ -15,11 +18,11 @@ let reconcile = projectRoot => {
| None => Path.(projectRoot / "package.json")
};

let operations = Lib.PesyConf.gen(projectRoot, manifestFile);
let operations = Lib.gen(projectRoot, manifestFile);

switch (operations) {
| [] => ()
| _ as operations => Lib.PesyConf.log(operations)
| _ as operations => Lib.log(operations)
};

print_endline(
Expand Down Expand Up @@ -50,183 +53,178 @@ let main = () => {
);
};

let main = () => {
PesyConf.(
try(main()) {
| BootstrappingError(message) =>
let message =
Pastel.(
let main = () =>
try(main()) {
| BootstrappingError(message) =>
let message =
Pastel.(
<Pastel>
<Pastel> "You have " </Pastel>
<Pastel color=Red> "not installed" </Pastel>
<Pastel> " esy\n" </Pastel>
<Pastel>
<Pastel> "You have " </Pastel>
<Pastel color=Red> "not installed" </Pastel>
<Pastel> " esy\n" </Pastel>
<Pastel>
"pesy works together with esy to simplify your workflow. Please install esy.\n"
</Pastel>
<Pastel> "You could try\n\n" </Pastel>
<Pastel bold=true> " npm install -g esy\n" </Pastel>
"pesy works together with esy to simplify your workflow. Please install esy.\n"
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| InvalidBinProperty(pkgName) =>
let mStr =
sprintf("Invalid value in subpackage %s's bin property\n", pkgName);
let message =
Pastel.(
<Pastel> "You could try\n\n" </Pastel>
<Pastel bold=true> " npm install -g esy\n" </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| InvalidBinProperty(pkgName) =>
let mStr =
sprintf("Invalid value in subpackage %s's bin property\n", pkgName);
let message =
Pastel.(
<Pastel>
<Pastel color=Red> mStr </Pastel>
<Pastel>
<Pastel color=Red> mStr </Pastel>
<Pastel>
"'bin' property is usually of the form { \"target.exe\": \"sourceFilename.re\" } "
</Pastel>
"'bin' property is usually of the form { \"target.exe\": \"sourceFilename.re\" } "
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| ShouldNotBeNull(e) =>
let message =
Pastel.(
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| ShouldNotBeNull(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Found null value for " </Pastel>
<Pastel bold=true> e </Pastel>
"\nExpected a non null value."
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| FatalError(e) =>
let message =
Pastel.(
<Pastel> <Pastel color=Red> "Fatal Error " </Pastel> e </Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| InvalidRootName(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Invalid root name!\n" </Pastel>
<Pastel> "Expected package name of the form " </Pastel>
<Pastel bold=true> "@myscope/foo-bar" </Pastel>
<Pastel> " or " </Pastel>
<Pastel bold=true> "foo-bar\n" </Pastel>
<Pastel> "Instead found " </Pastel>
<Pastel bold=true> e </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| GenericException(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Error: " </Pastel>
<Pastel> e </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| ImportsParserFailure(e) =>
/* TODO: Be more specific about which imports */
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Could not understand the imports\n" </Pastel>
<Pastel>
<Pastel color=Red> "Found null value for " </Pastel>
<Pastel bold=true> e </Pastel>
"\nExpected a non null value."
"There seems to be a syntax error in one of the imports"
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| FatalError(e) =>
let message =
Pastel.(
<Pastel> <Pastel color=Red> "Fatal Error " </Pastel> e </Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| InvalidRootName(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Invalid root name!\n" </Pastel>
<Pastel> "Expected package name of the form " </Pastel>
<Pastel bold=true> "@myscope/foo-bar" </Pastel>
<Pastel> " or " </Pastel>
<Pastel bold=true> "foo-bar\n" </Pastel>
<Pastel> "Instead found " </Pastel>
<Pastel bold=true> e </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| GenericException(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Error: " </Pastel>
<Pastel> e </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| ImportsParserFailure(e) =>
/* TODO: Be more specific about which imports */
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Could not understand the imports\n" </Pastel>
<Pastel>
"There seems to be a syntax error in one of the imports"
</Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| ResolveRelativePathFailure(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Could not find the library\n" </Pastel>
<Pastel> e </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| x =>
/* let message = Pastel.(<Pastel color=Red> "Failed" </Pastel>); */
/* fprintf(stderr, "%s", message); */
/* exit(-1); */
raise(x)
}
);
};
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| ResolveRelativePathFailure(e) =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red> "Could not find the library\n" </Pastel>
<Pastel> e </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
| x =>
/* let message = Pastel.(<Pastel color=Red> "Failed" </Pastel>); */
/* fprintf(stderr, "%s", message); */
/* exit(-1); */
raise(x)
};

/** DEPRECATED: Pesy is not supposed to be run in build env https://github.com/jchavarri/rebez/issues/4 **/
let pesy_build = () =>
PesyConf.(
ignore(
switch (Sys.getenv_opt("cur__root")) {
| Some(curRoot) =>
let buildTarget =
try(build(curRoot)) {
| BuildValidationFailures(failures) =>
let errorMessages =
String.concat(
"\n",
failures
|> List.map(
fun
| StaleDuneFile(f) => {
let duneFile =
Str.global_replace(
Str.regexp(curRoot ++ (Sys.unix ? "/" : "\\")),
"",
f,
);
sprintf(
" Dune file %s is stale",
Pastel.(<Pastel bold=true> duneFile </Pastel>),
ignore(
switch (Sys.getenv_opt("cur__root")) {
| Some(curRoot) =>
let buildTarget =
try(build(curRoot)) {
| BuildValidationFailures(failures) =>
let errorMessages =
String.concat(
"\n",
failures
|> List.map(
fun
| StaleDuneFile(f) => {
let duneFile =
Str.global_replace(
Str.regexp(curRoot ++ (Sys.unix ? "/" : "\\")),
"",
f,
);
}
| StaleOpamFile((o, n)) =>
sprintf(
" Project target name has changed. Found %s instead of %s",
Pastel.(<Pastel bold=true> o </Pastel>),
Pastel.(<Pastel bold=true> n </Pastel>),
),
),
);

fprintf(
stderr,
"%s",
Pastel.(
<Pastel color=Red>
"\n Found the following issues: \n\n"
</Pastel>
),
);
fprintf(stderr, "%s\n", errorMessages);
fprintf(
stderr,
"\n These can be fixed by running %s \n\n",
Pastel.(<Pastel color=Green> "esy pesy" </Pastel>),
" Dune file %s is stale",
Pastel.(<Pastel bold=true> duneFile </Pastel>),
);
}
| StaleOpamFile((o, n)) =>
sprintf(
" Project target name has changed. Found %s instead of %s",
Pastel.(<Pastel bold=true> o </Pastel>),
Pastel.(<Pastel bold=true> n </Pastel>),
),
),
);
exit(-1);
};

Sys.command("refmterr dune build -p " ++ buildTarget);
| None =>
let message =
Pastel.(
<Pastel>
fprintf(
stderr,
"%s",
Pastel.(
<Pastel color=Red>
"'pesy build' must be run the build environment only\n"
"\n Found the following issues: \n\n"
</Pastel>
<Pastel> "Try esy b pesy build" </Pastel>
</Pastel>
),
);
fprintf(stderr, "%s\n", errorMessages);
fprintf(
stderr,
"\n These can be fixed by running %s \n\n",
Pastel.(<Pastel color=Green> "esy pesy" </Pastel>),
);
fprintf(stderr, "%s\n", message);
exit(-1);
},
)
exit(-1);
};

Sys.command("refmterr dune build -p " ++ buildTarget);
| None =>
let message =
Pastel.(
<Pastel>
<Pastel color=Red>
"'pesy build' must be run the build environment only\n"
</Pastel>
<Pastel> "Try esy b pesy build" </Pastel>
</Pastel>
);
fprintf(stderr, "%s\n", message);
exit(-1);
},
);

let pesyLsLibs = () => {
Expand Down
5 changes: 3 additions & 2 deletions bin/dune
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
(executable (name Pesy) (public_name pesy)
(libraries pesy--esy-pesy.lib pesy--esy-pesy.utils cmdliner str findlib))
(executable (name Pesy) (modules (:standard)) (public_name pesy)
(libraries pesy--esy-pesy.errors pesy--esy-pesy.lib pesy--esy-pesy.utils
cmdliner str findlib))
6 changes: 0 additions & 6 deletions lib/PesyConf.rei → errors/Errors.re
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
type fileOperation;

type validationError =
| StaleDuneFile(string)
| StaleOpamFile((string, string));
Expand All @@ -13,7 +11,3 @@ exception ResolveRelativePathFailure(string);
exception InvalidBinProperty(string);
exception BuildValidationFailures(list(validationError));
exception ImportsParserFailure(unit);

let gen: (string, string) => list(fileOperation);
let log: list(fileOperation) => unit;
let validateDuneFiles: (string, string) => string;
2 changes: 2 additions & 0 deletions errors/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(library (name PesyEsyPesyErrors) (public_name pesy--esy-pesy.errors)
(modules (:standard)))
Loading

0 comments on commit 58db380

Please sign in to comment.