diff --git a/flake.nix b/flake.nix index c639acc231..8a82a8e03c 100644 --- a/flake.nix +++ b/flake.nix @@ -323,7 +323,6 @@ in flake-parts.lib.mkFlake {inherit inputs;} { imports = [ - ./tests ./templates ./v1/nix/modules/flake-parts/all-modules.nix ]; diff --git a/tests/default.nix b/tests/default.nix deleted file mode 100644 index 17809357d0..0000000000 --- a/tests/default.nix +++ /dev/null @@ -1,71 +0,0 @@ -{ - inputs, - self, - ... -}: { - perSystem = { - config, - pkgs, - system, - ... - }: let - b = builtins; - - callTests = f: - pkgs.callPackage f { - inherit self; - framework = config.d2n; - }; - in { - apps = { - tests-unit.type = "app"; - tests-unit.program = - b.toString - (callTests ./unit); - - tests-integration.type = "app"; - tests-integration.program = - b.toString - (callTests ./integration); - - tests-integration-d2n-flakes.type = "app"; - tests-integration-d2n-flakes.program = - b.toString - (callTests ./integration-d2n-flakes); - - tests-all.type = "app"; - tests-all.program = - b.toString - (config.d2n.utils.writePureShellScript - [ - pkgs.alejandra - pkgs.coreutils - pkgs.gitMinimal - pkgs.nix - ] - '' - echo "check for correct formatting" - WORKDIR=$(realpath ./.) - cd $TMPDIR - cp -r $WORKDIR ./repo - cd ./repo - ${config.apps.format.program} --fail-on-change - cd - - - echo "running unit tests" - ${config.apps.tests-unit.program} - - echo "running integration tests" - ${config.apps.tests-integration.program} - - echo "checking flakes under ./examples" - ${config.apps.tests-examples.program} - - echo "running nix flake check" - cd $WORKDIR - nix flake show >/dev/null - nix flake check - ''); - }; - }; -} diff --git a/tests/integration-d2n-flakes/default.nix b/tests/integration-d2n-flakes/default.nix deleted file mode 100644 index b649f30d60..0000000000 --- a/tests/integration-d2n-flakes/default.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ - self, - lib, - async, - bash, - coreutils, - git, - parallel, - nix, - framework, - ... -}: let - l = lib // builtins; - tests = ./tests; - testScript = - framework.utils.writePureShellScript - [ - async - bash - coreutils - git - nix - ] - '' - cd $TMPDIR - dir=$1 - shift - echo -e "\nrunning test $dir" - start_time=$(date +%s) - cp -r ${tests}/$dir/* . - chmod -R +w . - nix flake lock --override-input dream2nix ${../../.} - nix run .#resolveImpure || echo "no resolveImpure probably?" - nix build - nix flake check - end_time=$(date +%s) - elapsed=$(( end_time - start_time )) - echo -e "testing example for $dir took $elapsed seconds" - echo "$elapsed sec: $dir" >> $STATS_FILE - ''; -in - framework.utils.writePureShellScript - [ - coreutils - parallel - ] - '' - export STATS_FILE=$(mktemp) - if [ -z ''${1+x} ]; then - JOBS=''${JOBS:-$(nproc)} - parallel --halt now,fail=1 -j$JOBS -a <(ls ${tests}) ${testScript} - else - arg1=$1 - shift - ${testScript} $arg1 "$@" - fi - echo "done running flake integration tests" - echo -e "\nExecution times:" - cat $STATS_FILE | sort --numeric-sort - rm $STATS_FILE - '' diff --git a/tests/integration-d2n-flakes/tests/.gitignore b/tests/integration-d2n-flakes/tests/.gitignore deleted file mode 100644 index 301d47e19e..0000000000 --- a/tests/integration-d2n-flakes/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -flake.lock diff --git a/tests/integration-d2n-flakes/tests/nodejs_built-binary/flake.nix b/tests/integration-d2n-flakes/tests/nodejs_built-binary/flake.nix deleted file mode 100644 index b8ed026ecb..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_built-binary/flake.nix +++ /dev/null @@ -1,28 +0,0 @@ -# test: node.js built binary -# -# Detecting regressions of #235. -# -# Node.js builder was crashing if a binary defined in package.json -# bin section refers to a file that does not exist before the build step. -# -# 1. "package.json".bin.main = "./main.js" -# 2. `main.js` does not exist, but is created during the build -# 3. the default build script "package.json".scripts.build creates `main.js` -# during the buildPhase -# 4. the binary is linked to the bin directory in the installPhase -# -{ - inputs = { - dream2nix.url = "github:nix-community/dream2nix"; - }; - - outputs = { - self, - dream2nix, - }: (dream2nix.lib.makeFlakeOutputs { - systems = ["x86_64-linux"]; - config.projectRoot = ./.; - source = ./.; - autoProjects = true; - }); -} diff --git a/tests/integration-d2n-flakes/tests/nodejs_built-binary/package.json b/tests/integration-d2n-flakes/tests/nodejs_built-binary/package.json deleted file mode 100644 index dcd3860ea4..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_built-binary/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "test-built-binary", - "version": "1.0.0", - "bin": { - "main": "./main.js" - }, - "scripts": { - "build": "touch main.js" - } -} diff --git a/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/flake.nix b/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/flake.nix deleted file mode 100644 index dadfd37366..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/flake.nix +++ /dev/null @@ -1,29 +0,0 @@ -# test: yarn-lock evaluation with @git+ in versions -# -# Detecting regressions of #275. -# -# Evaluation of a package.json and a yarn.lock with special cases for -# versions would cause mismatches between the two: -# ''error: attribute '*' missing' -# -# 1. package.json has a dependency with a version starting with "@git+" -# 2. yarn resolves it in its yarn.lock file to the proper version and reference -# 3. the two are either not parsed correctly or mismatched on evaluation -# -{ - inputs = { - dream2nix.url = "github:nix-community/dream2nix"; - }; - - outputs = { - self, - dream2nix, - }: - dream2nix.lib.makeFlakeOutputs { - systems = ["x86_64-linux"]; - config.projectRoot = ./.; - packageOverrides = {}; - source = ./.; - autoProjects = true; - }; -} diff --git a/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/package.json b/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/package.json deleted file mode 100644 index f4002ab3b6..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "test-git-versions", - "version": "1.0.0", - "dependencies": { - "browser-image-resizer": "git+https://github.com/misskey-dev/browser-image-resizer#v2.2.1-misskey.2" - } -} diff --git a/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/yarn.lock b/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/yarn.lock deleted file mode 100644 index 5b3741f7cf..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_dependency-versions-mismatch/yarn.lock +++ /dev/null @@ -1,7 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -"browser-image-resizer@git+https://github.com/misskey-dev/browser-image-resizer#v2.2.1-misskey.2": - version "2.2.1-misskey.2" - resolved "git+https://github.com/misskey-dev/browser-image-resizer#a58834f5fe2af9f9f31ff115121aef3de6f9d416" diff --git a/tests/integration-d2n-flakes/tests/nodejs_direct-priority-over-transitive/flake.nix b/tests/integration-d2n-flakes/tests/nodejs_direct-priority-over-transitive/flake.nix deleted file mode 100644 index e1f9534fc8..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_direct-priority-over-transitive/flake.nix +++ /dev/null @@ -1,47 +0,0 @@ -# test: node.js direct dep priority over transitive dep -# -# Detecting regressions for #221. -# -# Node.js builder was linking the wrong version of a binary, -# if there was another dependency transitivelly depending on another version, -# this one would be resolved instead of the direct dependency. -# -# Dependencies: svgo@2, cssnano@4 (cssnano@4 -> svgo@1) -# -# 1. Dream2Nix normal build. -# 2. Get version of svgo in node.js path. (npm run get-version = svgo --version) -# 3. Check if this is the same version as the direct dependency. -# -{ - inputs = { - dream2nix.url = "github:nix-community/dream2nix"; - }; - - outputs = { - self, - dream2nix, - }: (dream2nix.lib.makeFlakeOutputs { - systems = ["x86_64-linux"]; - config.projectRoot = ./.; - source = ./.; - autoProjects = true; - packageOverrides = { - test = { - "check-linked-bin-version" = { - postInstall = '' - npm run get-version - VERSION=$(cat VERSION) - echo "$VERSION" - - if [ "$VERSION" = "2.8.0" ]; then - echo "correct version installed - direct dependency" - else - echo "wrong version installed - transitive dependency" - exit 1 - fi - ''; - }; - }; - }; - }); -} diff --git a/tests/integration-d2n-flakes/tests/nodejs_direct-priority-over-transitive/package.json b/tests/integration-d2n-flakes/tests/nodejs_direct-priority-over-transitive/package.json deleted file mode 100644 index c06d8fdc2b..0000000000 --- a/tests/integration-d2n-flakes/tests/nodejs_direct-priority-over-transitive/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "test", - "version": "1.0.0", - "scripts": { - "get-version": "svgo --version > VERSION" - }, - "devDependencies": { - "svgo": "2.8.0", - "cssnano": "4.1.10" - } -} diff --git a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/composer.json b/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/composer.json deleted file mode 100644 index 0fb246efc4..0000000000 --- a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/composer.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "raboof/php_transitive_with_target_dir", - "type": "project", - "require": { - "ml/json-ld": "^1.1" - }, - "authors": [ - { - "name": "Arnout Engelen", - "email": "arnout@bzzt.net" - } - ] -} diff --git a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/composer.lock b/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/composer.lock deleted file mode 100644 index bc3c3e1767..0000000000 --- a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/composer.lock +++ /dev/null @@ -1,123 +0,0 @@ -{ - "_readme": [ - "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", - "This file is @generated automatically" - ], - "content-hash": "4d38647ca76a14d3b8421dd8b0d462b7", - "packages": [ - { - "name": "ml/iri", - "version": "1.1.4", - "target-dir": "ML/IRI", - "source": { - "type": "git", - "url": "https://github.com/lanthaler/IRI.git", - "reference": "cbd44fa913e00ea624241b38cefaa99da8d71341" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lanthaler/IRI/zipball/cbd44fa913e00ea624241b38cefaa99da8d71341", - "reference": "cbd44fa913e00ea624241b38cefaa99da8d71341", - "shasum": "" - }, - "require": { - "lib-pcre": ">=4.0", - "php": ">=5.3.0" - }, - "type": "library", - "autoload": { - "psr-0": { - "ML\\IRI": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Markus Lanthaler", - "email": "mail@markus-lanthaler.com", - "homepage": "http://www.markus-lanthaler.com", - "role": "Developer" - } - ], - "description": "IRI handling for PHP", - "homepage": "http://www.markus-lanthaler.com", - "keywords": [ - "URN", - "iri", - "uri", - "url" - ], - "support": { - "issues": "https://github.com/lanthaler/IRI/issues", - "source": "https://github.com/lanthaler/IRI/tree/master" - }, - "time": "2014-01-21T13:43:39+00:00" - }, - { - "name": "ml/json-ld", - "version": "1.2.1", - "source": { - "type": "git", - "url": "https://github.com/lanthaler/JsonLD.git", - "reference": "537e68e87a6bce23e57c575cd5dcac1f67ce25d8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/lanthaler/JsonLD/zipball/537e68e87a6bce23e57c575cd5dcac1f67ce25d8", - "reference": "537e68e87a6bce23e57c575cd5dcac1f67ce25d8", - "shasum": "" - }, - "require": { - "ext-json": "*", - "ml/iri": "^1.1.1", - "php": ">=5.3.0" - }, - "require-dev": { - "json-ld/tests": "1.0", - "phpunit/phpunit": "^4" - }, - "type": "library", - "autoload": { - "psr-4": { - "ML\\JsonLD\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Markus Lanthaler", - "email": "mail@markus-lanthaler.com", - "homepage": "http://www.markus-lanthaler.com", - "role": "Developer" - } - ], - "description": "JSON-LD Processor for PHP", - "homepage": "http://www.markus-lanthaler.com", - "keywords": [ - "JSON-LD", - "jsonld" - ], - "support": { - "issues": "https://github.com/lanthaler/JsonLD/issues", - "source": "https://github.com/lanthaler/JsonLD/tree/1.2.1" - }, - "time": "2022-09-29T08:45:17+00:00" - } - ], - "packages-dev": [], - "aliases": [], - "minimum-stability": "stable", - "stability-flags": [], - "prefer-stable": false, - "prefer-lowest": false, - "platform": [], - "platform-dev": [], - "plugin-api-version": "2.3.0" -} diff --git a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/flake.nix b/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/flake.nix deleted file mode 100644 index 785ea30573..0000000000 --- a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/flake.nix +++ /dev/null @@ -1,25 +0,0 @@ -# ml/json-ld depends on ml/iri, and ml/iri uses the (deprecated) -# `target-dir` attribute, which appears to cause a mismatch between -# dream2nix and composer behavior and makes the build fail. -# -# Since target-dir is deprecated and will be removed in a future -# version of ml/iri anyway, a neat solution is to override the -# package and add a prePatch phase that drops the attribute, -# fixing the build: -{ - inputs.dream2nix.url = "github:nix-community/dream2nix"; - outputs = inp: - inp.dream2nix.lib.makeFlakeOutputs { - systems = ["x86_64-linux"]; - config.projectRoot = ./.; - source = ./.; - projects = ./projects.toml; - packageOverrides = { - "^ml.iri.*".updated.overrideAttrs = old: { - prePatch = '' - cat composer.json | grep -v target-dir | sponge composer.json - ''; - }; - }; - }; -} diff --git a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/projects.toml b/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/projects.toml deleted file mode 100644 index 4b92deaea8..0000000000 --- a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/projects.toml +++ /dev/null @@ -1,18 +0,0 @@ -# projects.toml file describing inputs for dream2nix -# -# To re-generate this file, run: -# nix run .#detect-projects $source -# ... where `$source` points to the source of your project. -# -# If the local flake is unavailable, alternatively execute the app from the -# upstream dream2nix flake: -# nix run github:nix-community/dream2nix#detect-projects $source - -["raboof/php_transitive_with_target_dir"] -name = "raboof/php_transitive_with_target_dir" -relPath = "" -subsystem = "php" -translator = "composer-lock" -translators = [ "composer-lock", "composer-json",] - -["raboof/php_transitive_with_target_dir".subsystemInfo] diff --git a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/test.php b/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/test.php deleted file mode 100644 index 25994982fa..0000000000 --- a/tests/integration-d2n-flakes/tests/php_transitive_with_target_dir/test.php +++ /dev/null @@ -1,5 +0,0 @@ - diff --git a/tests/integration/default.nix b/tests/integration/default.nix deleted file mode 100644 index e58eee3d3e..0000000000 --- a/tests/integration/default.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ - self, - lib, - async, - bash, - coreutils, - git, - parallel, - nix, - pkgs, - framework, - ... -}: let - l = lib // builtins; - testDirs = l.attrNames (l.readDir ./tests); - testScripts = - map - ( - dir: - pkgs.callPackage - (./tests + "/${dir}") - {inherit self framework;} - ) - testDirs; - testScriptsFile = pkgs.writeText "scripts-list" (l.concatStringsSep "\n" testScripts); - execTest = - framework.utils.writePureShellScript - [ - bash - coreutils - ] - '' - cd $TMPDIR - test=$1 - shift - echo -e "\nrunning test $test" - start_time=$(date +%s) - - bash "$test" - - end_time=$(date +%s) - elapsed=$(( end_time - start_time )) - echo -e "testing example for $test took $elapsed seconds" - echo "$elapsed sec: $test" >> $STATS_FILE - ''; -in - framework.utils.writePureShellScript - [ - bash - coreutils - parallel - ] - '' - export STATS_FILE=$(mktemp) - JOBS=''${JOBS:-$(nproc)} - parallel --halt now,fail=1 -j$JOBS -a ${testScriptsFile} ${execTest} - echo "done running integration tests" - echo -e "\nExecution times:" - cat $STATS_FILE | sort --numeric-sort - rm $STATS_FILE - '' diff --git a/tests/integration/tests/contribute/default.nix b/tests/integration/tests/contribute/default.nix deleted file mode 100644 index 2e88ae0bfa..0000000000 --- a/tests/integration/tests/contribute/default.nix +++ /dev/null @@ -1,35 +0,0 @@ -{ - lib, - pkgs, - self, - framework, - ... -}: let - l = lib // builtins; -in - framework.utils.writePureShellScript - (with pkgs; [ - coreutils - nix - ]) - '' - # create working dirs - mkdir $TMPDIR/dream2nix - - # checkout dream2nix source code - cd $TMPDIR/dream2nix - cp -r ${self}/* . - chmod -R +w . - - # fake git - function git(){ - true - } - - set -x - source ${self}/docs/src/contributing/00-declare-variables.sh - source ${self}/docs/src/contributing/01-initialize-templates.sh - source ${self}/docs/src/contributing/02-initialize-example-flake.sh - source ${self}/docs/src/contributing/03-add-files-to-git.sh - source ${self}/docs/src/contributing/04-test-example-flake.sh - '' diff --git a/tests/integration/tests/contribute/my-flake.nix b/tests/integration/tests/contribute/my-flake.nix deleted file mode 100644 index 8331e2eaa6..0000000000 --- a/tests/integration/tests/contribute/my-flake.nix +++ /dev/null @@ -1,36 +0,0 @@ -{ - inputs = { - dream2nix.url = "github:nix-community/dream2nix"; - nixpkgs.follows = "dream2nix/nixpkgs"; - flake-parts.url = "github:hercules-ci/flake-parts"; - src.url = "github:nmattia/niv"; - src.flake = false; - }; - - outputs = { - self, - dream2nix, - flake-parts, - src, - ... - }: - flake-parts.lib.mkFlake {inherit self;} { - systems = ["x86_64-linux"]; - imports = [dream2nix.flakeModuleBeta]; - - perSystem = {config, ...}: { - # define an input for dream2nix to generate outputs for - dream2nix.inputs."niv" = { - source = src; - projects.my-project = { - name = "my-project"; - subsystem = "my-subsystem"; - translator = "my-pure-translator"; - }; - }; - packages = { - inherit (config.dream2nix.outputs.niv.packages) default; - }; - }; - }; -} diff --git a/tests/integration/tests/verify-dream-lock-example/default.nix b/tests/integration/tests/verify-dream-lock-example/default.nix deleted file mode 100644 index 9ae025e363..0000000000 --- a/tests/integration/tests/verify-dream-lock-example/default.nix +++ /dev/null @@ -1,26 +0,0 @@ -{ - lib, - pkgs, - framework, - self, - ... -}: let - l = lib // builtins; - specificationsDir = ../../../../src/specifications; -in - framework.utils.writePureShellScript - (with pkgs; [ - coreutils - nix - ]) - '' - cd $TMPDIR - cp -r ${specificationsDir}/* . - chmod -R +w . - specsDir=$(realpath .) - ${pkgs.python3.pkgs.jsonschema}/bin/jsonschema \ - --instance $specsDir/dream-lock-example.json \ - --output pretty \ - --base-uri file:$specsDir/ \ - $specsDir/dream-lock-schema.json - '' diff --git a/tests/unit/default.nix b/tests/unit/default.nix deleted file mode 100644 index 5f44298e1a..0000000000 --- a/tests/unit/default.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ - self, - lib, - coreutils, - nix, - git, - python3, - framework, - ... -}: let - l = lib // builtins; - - pythonEnv = python3.withPackages (ps: - with ps; [ - pytest - pytest-xdist - ]); -in - framework.utils.writePureShellScript - [ - coreutils - nix - git - ] - '' - export dream2nixSrc=${../../.}/src - TESTDIR="$TMPDIR/tests/unit" - mkdir -p $TESTDIR - ln -sf ${framework.utils.scripts.nixFFI} "$TESTDIR/nix_ffi.py" - cp -r ${self}/tests/unit/* $TESTDIR - ${pythonEnv}/bin/pytest $TESTDIR -n $(nproc) -v "$@" - '' diff --git a/tests/unit/test_dream_lock.py b/tests/unit/test_dream_lock.py deleted file mode 100644 index fae61b07ed..0000000000 --- a/tests/unit/test_dream_lock.py +++ /dev/null @@ -1,55 +0,0 @@ -import pytest -import nix_ffi - -exampleDreamLock = dict( - _generic=dict( - defaultPackage="example", - packages=dict( - example="1.2.3", - ), - subsystem="nodejs", - _subsystemAttrs={}, - ), - dependencies={}, - cyclicDependencies={}, - sources=dict( - example={ - "1.2.3": dict( - type="path", - rootName=None, - rootVersion=None, - relPath="a/b/c", - ), - }, - ), -) - - -def test_dream_lock_inject(): - result = nix_ffi.callNixFunction( - "utils.dream-lock.injectDependencies", - dreamLock=exampleDreamLock, - inject=dict(example={"1.2.3": [["injected-package", "1.0.0"]]}), - ) - assert result["dependencies"]["example"]["1.2.3"] == [ - dict( - name="injected-package", - version="1.0.0", - ) - ] - - -def test_dream_lock_replace_root_sources(): - result = nix_ffi.callNixFunction( - "utils.dream-lock.replaceRootSources", - dreamLock=exampleDreamLock, - newSourceRoot=dict( - type="http", - url="something", - ), - ) - assert result["sources"]["example"]["1.2.3"] == dict( - type="http", - url="something", - dir="a/b/c", - ) diff --git a/tests/unit/test_pure_translators.py b/tests/unit/test_pure_translators.py deleted file mode 100644 index ad18f161e3..0000000000 --- a/tests/unit/test_pure_translators.py +++ /dev/null @@ -1,309 +0,0 @@ -import nix_ffi -import os -import pytest - - -def get_projects_to_test(): - tests = nix_ffi.eval( - "translators", - wrapper_code=""" - {result, ...}: let - lib = (import {}).lib; - l = lib // builtins; - in - l.flatten ( - l.map - ( - translator: - l.map - (source: { - source = l.toString source; - translator = translator.name; - inherit (translator) subsystem type; - }) - (translator.generateUnitTestsForProjects or []) - ) - (l.attrValues result) - ) - """, - ) - result = [] - for test in tests: - if test["type"] == "all": - continue - result.append( - dict( - project=dict( - name="test", - relPath="", - translator=test["translator"], - subsystemInfo={}, - ), - translator=test["translator"], - source=test["source"], - subsystem=test["subsystem"], - type=test["type"], - ) - ) - return result - - -projects = get_projects_to_test() - - -def check_format_dependencies(dependencies): - assert isinstance(dependencies, list) - for dep in dependencies: - assert set(dep.keys()) == {"name", "version"} - assert isinstance(dep["name"], str) - assert len(dep["name"]) > 0 - assert isinstance(dep["version"], str) - assert len(dep["version"]) > 0 - - -def check_format_sourceSpec(sourceSpec): - assert isinstance(sourceSpec, dict) - assert "type" in sourceSpec - - -@pytest.mark.parametrize("p", projects) -def test_packageName(p): - defaultPackage = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - result.inputs.defaultPackage - """, - ) - assert isinstance(defaultPackage, str) - assert len(defaultPackage) > 0 - - -@pytest.mark.parametrize("p", projects) -def test_exportedPackages(p): - exportedPackages = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - result.inputs.exportedPackages - """, - ) - assert isinstance(exportedPackages, dict) - assert len(exportedPackages) > 0 - - -@pytest.mark.parametrize("p", projects) -def test_extraObjects(p): - extraObjects = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - result.inputs.extraObjects - """, - ) - assert isinstance(extraObjects, list) - for extra_obj in extraObjects: - assert set(extra_obj.keys()) == { - "name", - "version", - "dependencies", - "sourceSpec", - } - assert isinstance(extra_obj["name"], str) - assert len(extra_obj["name"]) > 0 - assert isinstance(extra_obj["version"], str) - assert len(extra_obj["version"]) > 0 - check_format_dependencies(extra_obj["dependencies"]) - check_format_sourceSpec(extra_obj["sourceSpec"]) - - -@pytest.mark.parametrize("p", projects) -def test_location(p): - location = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - result.inputs.location - """, - ) - assert isinstance(location, str) - - -@pytest.mark.parametrize("p", projects) -def test_serializedRawObjects(p): - serializedRawObjects = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, lib, ...}: - let - len = lib.length result.inputs.serializedRawObjects; - in - # for performance reasons check only first/last 10 items of the list - (lib.sublist 0 10 result.inputs.serializedRawObjects) - ++ (lib.sublist (lib.max (len - 10) 0) len result.inputs.serializedRawObjects) - """, - ) - assert isinstance(serializedRawObjects, list) - assert len(serializedRawObjects) > 0 - for raw_obj in serializedRawObjects: - assert isinstance(raw_obj, dict) - - -@pytest.mark.parametrize("p", projects) -def test_subsystemName(p): - subsystemName = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - result.inputs.subsystemName - """, - ) - assert isinstance(subsystemName, str) - assert len(subsystemName) > 0 - - -@pytest.mark.parametrize("p", projects) -def test_subsystemAttrs(p): - subsystemAttrs = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - builtins.trace result.inputs.subsystemAttrs - result.inputs.subsystemAttrs - """, - ) - assert isinstance(subsystemAttrs, dict) - - -@pytest.mark.parametrize("p", projects) -def test_translatorName(p): - translatorName = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, ...}: - result.inputs.translatorName - """, - ) - assert isinstance(translatorName, str) - assert len(translatorName) > 0 - - -@pytest.mark.parametrize("p", projects) -def test_extractors(p): - finalObjects = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, dlib, ...}: - let - l = builtins; - inputs = result.inputs; - rawObjects = inputs.serializedRawObjects; - s = dlib.simpleTranslate2; - - finalObjects = s.mkFinalObjects rawObjects inputs.extractors; - allDependencies = s.makeDependencies finalObjects; - exportedFinalObjects = - s.mkExportedFinalObjects finalObjects inputs.exportedPackages; - relevantFinalObjects = - s.mkRelevantFinalObjects exportedFinalObjects allDependencies; - in - relevantFinalObjects ++ (inputs.extraObjects or []) - """, - ) - assert isinstance(finalObjects, list) - assert len(finalObjects) > 0 - for finalObj in finalObjects: - assert (set(finalObj.keys()) - {"rawObj", "key"}) == { - "name", - "version", - "sourceSpec", - "dependencies", - } - check_format_dependencies(finalObj["dependencies"]) - check_format_sourceSpec(finalObj["sourceSpec"]) - - -@pytest.mark.parametrize("p", projects) -def test_keys(p): - objectsByKey = nix_ffi.eval( - f"translatorsBySubsystem.{p['subsystem']}.{p['translator']}.finalTranslate", - params=dict( - project=p["project"], - source=p["source"], - ), - wrapper_code=""" - {result, dlib, ...}: - let - l = builtins; - inputs = result.inputs; - rawObjects = inputs.serializedRawObjects; - s = dlib.simpleTranslate2; - - finalObjects = s.mkFinalObjects rawObjects inputs.extractors; - allDependencies = s.makeDependencies finalObjects; - exportedFinalObjects = - s.mkExportedFinalObjects finalObjects inputs.exportedPackages; - relevantFinalObjects = - s.mkRelevantFinalObjects exportedFinalObjects allDependencies; - - objectsByKey = - l.mapAttrs - (key: keyFunc: - l.foldl' - (merged: finalObj: - merged - // {"${keyFunc finalObj.rawObj finalObj}" = finalObj;}) - {} - relevantFinalObjects) - inputs.keys; - in - objectsByKey - """, - ) - assert isinstance(objectsByKey, dict) - for key_name, objects in objectsByKey.items(): - for finalObj in objects.values(): - assert set(finalObj.keys()) - {"rawObj", "key"} == { - "name", - "version", - "sourceSpec", - "dependencies", - } - check_format_dependencies(finalObj["dependencies"]) - check_format_sourceSpec(finalObj["sourceSpec"]) diff --git a/tests/unit/test_source_shortcuts.py b/tests/unit/test_source_shortcuts.py deleted file mode 100644 index bf55dd69de..0000000000 --- a/tests/unit/test_source_shortcuts.py +++ /dev/null @@ -1,78 +0,0 @@ -import pytest -import nix_ffi - - -@pytest.mark.parametrize( - "shortcut, expected", - [ - ( - "https://foo", - dict( - type="http", - url="https://foo", - ), - ), - ( - "http://foo/bar", - dict( - type="http", - url="http://foo/bar", - ), - ), - ( - "github:owner/repo/v1.2.3", - dict( - type="github", - owner="owner", - repo="repo", - rev="v1.2.3", - ), - ), - # with arguments - ( - "git+ssh://github.com/owner/repo?rev=refs/heads/v1.2.3&dir=sub/dir", - dict( - type="git", - url="ssh://github.com/owner/repo", - rev="refs/heads/v1.2.3", - dir="sub/dir", - ), - ), - ( - "http://foo/bar?kwarg1=foo&dir=sub/dir", - dict( - type="http", - url="http://foo/bar?kwarg1=foo", - dir="sub/dir", - ), - ), - ( - "github:owner/repo/v1.2.3?kwarg1=foo&dir=sub/dir", - dict( - type="github", - owner="owner", - repo="repo", - rev="v1.2.3", - kwarg1="foo", - dir="sub/dir", - ), - ), - ( - "github:photoview/photoview/master?dir=lol", - dict( - type="github", - owner="photoview", - repo="photoview", - rev="master", - dir="lol", - ), - ), - ], -) -def test_translateShortcut(shortcut, expected): - result = nix_ffi.callNixFunction( - "functions.fetchers.translateShortcut", - shortcut=shortcut, - computeHash=False, - ) - assert result == expected diff --git a/tests/unit/test_utils.py b/tests/unit/test_utils.py deleted file mode 100644 index 655a60c399..0000000000 --- a/tests/unit/test_utils.py +++ /dev/null @@ -1,13 +0,0 @@ -import pytest -import nix_ffi - - -@pytest.mark.parametrize( - "expected, versions", - [ - ("3", ["2", "3", "1"]), - ], -) -def test_latestVersion(expected, versions): - result = nix_ffi.callNixFunction("dlib.latestVersion", versions=versions) - assert result == expected