Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hg source and Unit test cases #23

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ build: clean

.PHONY: check
check: $(BINARY)
@crystal spec
@crystal spec --tag ~online

.PHONY: clean
clean:
@rm -f $(BINARY)

.PHONY: run
run: $(BINARY)
$(BINARY)
$(BINARY)
52 changes: 47 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,72 @@
# crystal2nix

Helps nixify crystal projects.
[<img src="https://nixos.org/logo/nixos-logo-only-hires.png" width="200" align="right" alt="NixOS">](https://nixos.org)

# Crystal2Nix

Crystal2Nix is a tool designed to generate Nix expressions for Crystal projects. It simplifies the process of managing dependencies and building Crystal applications within the Nix ecosystem.

## Features

- Automatically generates Nix expressions from `shard.yml` files.
- Supports Crystal projects with various dependencies.
- Building and managing Crystal applications.

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Testing](#testing)
- [Contributing](#contributing)
- [License](#license)

## Installation

### Prerequisites

- [Nix](https://nixos.org/download.html) installed on your system.
- [Crystal](https://crystal-lang.org/install/) programming language installed.
>>>>>>> 0e63fe2 (init at 0.1.0)

## Installation

You don't need to install it. With nix installed you can just run it:
You don't need to install crystal2nix manually. With Nix installed on your system, you can run it directly using the following command:

`nix-shell -p crystal2nix --run crystal2nix`

## Usage

To generate a Nix expression for your Crystal project, simply run:

`crystal2nix`

## Development
## Testing

Unit Tests: These tests can be run within the Nix sandbox without requiring network connectivity.

`make check ` # Runs unit tests

## Future plans

We will welcome all help with open arms!
Support for Fossil resources: Expanding source control compatibility.
Additional integration test cases: Enhancing the robustness of our test suite.

## Contributing

We value contributions from the community. If you have suggestions, bug reports, or improvements, please submit them through GitHub issues or pull requests. Your involvement helps us make crystal2nix better for everyone.

1. Fork it (<https://github.com/your-github-user/crystal2nix/fork>)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request

## License

crystal2nix is licensed under the MIT License. You are free to use, modify, and distribute this software under the terms of this license.

## Contributors

- [Michael Fellinger](https://github.com/manveru)
- [Peter Hoeg](https://github.com/peterhoeg)
- [Vidhvath J](https://github.com/vidhvath28)

115 changes: 115 additions & 0 deletions spec/repo_git_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
require "./spec_helper"

Spectator.describe Crystal2Nix::Repo do
context "commit" do
let(:with_commit) {
<<-EOF
git: https://github.com/cadmiumcr/transliterator.git
version: 0.1.0+git.commit.46c4c14594057dbcfaf27e7e7c8c164d3f0ce3f1
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit))
}

it "should have the commit as revision" do
expect(repo.rev).to eq("46c4c14594057dbcfaf27e7e7c8c164d3f0ce3f1")
end
end

context "explicit version" do
let(:with_version) {
<<-EOF
git: https://github.com/crystal-lang/json_mapping.cr.git
version: 0.1.1
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_version))
}

it "should prefix version references with a v" do
expect(repo.rev).to eq("v0.1.1")
end
end

context "semver with pre-release" do
let(:with_pre_release) {
<<-EOF
git: https://github.com/crystal-lang/crystal.git
version: 1.0.0-beta1
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_pre_release))
}

it "should handle semver with pre-release correctly" do
expect(repo.rev).to eq("v1.0.0-beta1")
end
end

context "semver with build metadata" do
let(:with_build_metadata) {
<<-EOF
git: https://github.com/crystal-lang/crystal.git
version: 1.0.0+20130313144700
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_build_metadata))
}

it "should handle semver with build metadata correctly" do
expect(repo.rev).to eq("v1.0.0+20130313144700")
end
end

context "git commit in version" do
let(:with_commit_version) {
<<-EOF
git: https://github.com/crystal-lang/crystal.git
version: 1.0.0+git.commit.abcdef1234567890
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit_version))
}

it "should handle git commit in version correctly" do
expect(repo.rev).to eq("abcdef1234567890")
end
end

context "malformed yaml" do
let(:malformed_yaml) {
<<-EOF
git: https://github.com/crystal-lang/crystal.git
version 1.0.0
EOF
}

it "should raise an error for malformed YAML" do
expect_raises(YAML::ParseException) do
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(malformed_yaml))
end
end
end

context "empty file" do
let(:empty_file_content) {
""
}

it "should raise an error for empty file" do
expect_raises(YAML::ParseException) do
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(empty_file_content))
end
end
end
end
103 changes: 103 additions & 0 deletions spec/repo_mercurial_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
require "./spec_helper"

Spectator.describe Crystal2Nix::Repo do
context "commit" do
let(:with_commit) {
<<-EOF
hg: https://selenic.com/repo/hello
version: 0.1.0+hg.commit.a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit))
}

it "should have the commit as revision" do
expect(repo.rev).to eq("a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0")
end
end

context "explicit version" do
let(:with_version) {
<<-EOF
hg: https://selenic.com/repo/hello
version: 2.0.0
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_version))
}

it "should prefix version references with a v" do
expect(repo.rev).to eq("v2.0.0")
end
end

context "semver with pre-release" do
let(:with_pre_release) {
<<-EOF
hg: https://selenic.com/repo/hello
version: 1.2.3-beta.1
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_pre_release))
}

it "should handle semver with pre-release correctly" do
expect(repo.rev).to eq("v1.2.3-beta.1")
end
end

context "semver with build metadata" do
let(:with_build_metadata) {
<<-EOF
hg: https://selenic.com/repo/hello
version: 1.0.0+build.12345
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_build_metadata))
}

it "should handle semver with build metadata correctly" do
expect(repo.rev).to eq("v1.0.0+build.12345")
end
end

context "hg commit in version" do
let(:with_commit_version) {
<<-EOF
hg: https://selenic.com/repo/hello
version: 1.0.0+hg.commit.abcdef1234567890abcdef1234567890abcdef12
EOF
}

let(:repo) {
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit_version))
}

it "should handle hg commit in version correctly" do
expect(repo.rev).to eq("abcdef1234567890abcdef1234567890abcdef12")
end
end

context "malformed yaml" do
let(:malformed_yaml) {
<<-EOF
hg: https://selenic.com/repo/hello
version 1.0.0
EOF
}

it "should raise an error for malformed YAML" do
expect_raises(YAML::ParseException) do
Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(malformed_yaml))
end
end
end
end
37 changes: 0 additions & 37 deletions spec/repo_spec.cr

This file was deleted.

5 changes: 0 additions & 5 deletions src/crystal2nix.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# This module defines the Crystal2Nix project, which converts Crystal project dependencies
# into Nix expressions for use with the Nix package manager. The project leverages various
# dependencies such as JSON, YAML, URI parsing, and a custom version management module.
# The main functionality is organized into separate components like data handling,
# repository management, and worker processes.
require "json"
require "yaml"
require "option_parser"
Expand Down
5 changes: 3 additions & 2 deletions src/data.cr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Crystal2Nix
class PrefetchJSON
class GitPrefetchJSON
include JSON::Serializable

property sha256 : String
Expand All @@ -15,7 +15,8 @@ module Crystal2Nix
class Shard
include YAML::Serializable

property git : String
property git : String?
property hg : String?
property version : String
end
end
Loading