Skip to content

Commit

Permalink
v0.1.2: add smoke test to derivation (#6)
Browse files Browse the repository at this point in the history
* test: add smoke test in derivation. bump version to 0.1.2

* change workflow trigger

* aggregate matrix jobs results

* indent

* fix conditional for cancelled jobs
  • Loading branch information
aakropotkin authored Jul 26, 2023
1 parent ebe559a commit d3ba8a0
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 43 deletions.
19 changes: 14 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
name: Test
on:
workflow_dispatch:
push:
branches:
- main
paths:
- '**'
- '!**/README*'
- '!**/CONTRIBUTING*'

pull_request:
types: [opened, synchronize, reopened]
paths:
- '**'
- '!**/README*'
- '!**/CONTRIBUTING*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
Expand Down Expand Up @@ -60,3 +56,16 @@ jobs:

- name: Run Tests
run: nix develop --no-update-lock-file --command make check -j4

all-tests-success:
if: ${{ always() }}
runs-on: ubuntu-latest
name: Tests ( All Systems )
needs: all-tests
steps:
- if: >-
${{
contains( needs.*.result, 'failure' ) ||
contains( needs.*.result, 'cancelled' )
}}
run: exit 1
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 22 additions & 20 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,6 @@ static const char usageMsg[] =
int
main( int argc, char * argv[], char ** envp )
{
nix::initNix();
nix::initGC();

nix::evalSettings.pureEval = false;

nix::EvalState state( {}, nix::openStore() );

char cmd = '\0';
char * arg = nullptr;

Expand Down Expand Up @@ -313,24 +306,34 @@ main( int argc, char * argv[], char ** envp )
}
}

/* Handle early to avoid initializing `nix' globals. */
if ( cmd == 'h' )
{
std::cout << usageMsg << std::endl << std::endl
<< "Options:" << std::endl
<< " -r <FLAKE-URI|JSON> parseAndResolveRef" << std::endl
<< " -l <FLAKE-URI|JSON> lockFlake" << std::endl
<< " -i INSTALLABLE-URI parseAndResolveRef" << std::endl
<< " -u URI parseURI" << std::endl
<< " --usage show usage message" << std::endl
<< " -h,--help show this message" << std::endl;
return EXIT_SUCCESS;
}

/* Initialize `nix' globals. */
nix::initNix();
nix::initGC();

nix::evalSettings.pureEval = false;

nix::EvalState state( {}, nix::openStore() );

switch ( cmd )
{
case 'r': j = parseAndResolveRef( state, arg ); break;
case 'l': j = lockFlake( state, arg ); break;
case 'i': j = parseInstallable( state, arg ); break;
case 'u': j = parseURI( arg ); break;
case 'h':
std::cout << usageMsg << std::endl << std::endl
<< "Options:" << std::endl
<< " -r <FLAKE-URI|JSON> parseAndResolveRef" << std::endl
<< " -l <FLAKE-URI|JSON> lockFlake" << std::endl
<< " -i INSTALLABLE-URI parseAndResolveRef" << std::endl
<< " -u URI parseURI" << std::endl
<< " --usage show usage message" << std::endl
<< " -h,--help show this message" << std::endl;
return EXIT_SUCCESS;
break;

default:
std::cerr << "Unrecognized command flag: " << argv[1] << std::endl
<< usageMsg << std::endl;
Expand All @@ -339,7 +342,6 @@ main( int argc, char * argv[], char ** envp )
break;
}


std::cout << j.dump() << std::endl;

return EXIT_SUCCESS;
Expand Down
34 changes: 19 additions & 15 deletions pkg-fun.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,12 @@
, jq
}: let

boost_CFLAGS = "-I" + boost + "/include";
libExt = stdenv.hostPlatform.extensions.sharedLibrary;
nix_INCDIR = nix.dev + "/include";
batsWith = bats.withLibraries ( p: [
p.bats-assert
p.bats-file
p.bats-support
] );
batsWith =
bats.withLibraries ( p: [p.bats-assert p.bats-file p.bats-support] );

in stdenv.mkDerivation {
pname = "parser-util";
version = "0.1.1";
version = "0.1.2";
src = builtins.path {
path = ./.;
filter = name: type: let
Expand All @@ -48,7 +42,9 @@ in stdenv.mkDerivation {
notResult = ( builtins.match "result(-*)?" bname ) == null;
in notIgnored && notObject && notResult;
};
inherit boost_CFLAGS nix_INCDIR libExt;
boost_CFLAGS = "-I" + boost + "/include";
libExt = stdenv.hostPlatform.extensions.sharedLibrary;
nix_INCDIR = nix.dev + "/include";
nativeBuildInputs = [
# required for builds:
pkg-config
Expand All @@ -58,11 +54,6 @@ in stdenv.mkDerivation {
jq
];
buildInputs = [nlohmann_json nix.dev boost];
makeFlags = [
"libExt='${libExt}'"
"boost_CFLAGS='${boost_CFLAGS}'"
"nix_INCDIR='${nix_INCDIR}'"
];
configurePhase = ''
runHook preConfigure;
export PREFIX="$out";
Expand All @@ -71,7 +62,20 @@ in stdenv.mkDerivation {
fi
runHook postConfigure;
'';

# Real tests require internet connection and cannot be run in a sandbox.
# Still we do a smoke test running `parser-util --help' to catch low hanging
# issues like dynamic library resolution and init processes.
doInstallCheck = false;
doCheck = true;
checkPhase = ''
runHook preCheck;
if ! ./bin/parser-util --help >/dev/null; then
echo "FAIL: parser-util --help" >&2;
exit 1;
fi
runHook postCheck;
'';
}


Expand Down

0 comments on commit d3ba8a0

Please sign in to comment.